I would like to defer the file commit's when i use the SDK upload session.
This is possible with the API : https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0
{
"item": {
"#microsoft.graph.conflictBehavior": "rename"
},
"deferCommit": true
}
But in the SDK : https://learn.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=csharp
I couldn't find the equivalent in DriveItemUploadableProperties object
public class DriveItemUploadableProperties
{
public DriveItemUploadableProperties();
public string Description { get; set; }
public long? FileSize { get; set; }
public FileSystemInfo FileSystemInfo { get; set; }
public string Name { get; set; }
public IDictionary<string, object> AdditionalData { get; set; }
public string ODataType { get; set; }
}
How do i send the deferCommit flag and how do i send the completing flag ?
Edit 1 :
I've try :
DriveItemUploadableProperties properties = new DriveItemUploadableProperties
{
ODataType = null,
AdditionalData = new Dictionary<string, object>
{
{ "#microsoft.graph.conflictBehavior", "replace" },
{"deferCommit", true}
}
};
but it doesn't work
The deferCommit property isn't a member of the driveItemUploadableProperties class. This property should be set as part of the AdditionalData of DriveItemUploadableProperties. Please see documentation on completing a file for details on how to explicitly complete the upload.
This might look something like this:
AdditionalData = new Dictionary<string, object>
{
{ "#microsoft.graph.conflictBehavior", "replace" },
{"deferCommit", true}
},
Let me know whether this helps and if you have further questions.
Related
I have some message in the API response. I want to return the message to user. I cannot find how can I do it.
Sample Controller
[HttpGet]
public async Task<IActionResult> ListCountries()
{
List<Country> countries = new List<Country>();
var response = await _client.GetAsync("countries/getall");
if (response.IsSuccessStatusCode)
{
string apiResponse = await response.Content.ReadAsStringAsync();
var JsonData = JsonConvert.DeserializeObject<JsonCountryData>(apiResponse);
countries = JsonData.Data;
}
return View(countries);
}
Country Model
namespace EVisaProject.Models
{
public class CountryModel
{
public int Id { get; set; }
public string CountryName { get; set; }
}
public class JsonCountryData
{
public List<CountryModel> Data { get; set; }
}
}
API
Because you're not de-serializing the property. Look at the object you're de-serializing the JSON data into:
public class JsonCountryData
{
public List<CountryModel> Data { get; set; }
}
Notice that it contains a property called Data. Which is why you can access the Data property. You can't access the Success or Message properties because you haven't added them to the model, so they don't exist.
In order to use them, add them to the model so they exist:
public class JsonCountryData
{
public List<CountryModel> Data { get; set; }
public bool Success { get; set; }
public string Message { get; set; }
}
Once they exist, you'll be able to use them:
var JsonData = JsonConvert.DeserializeObject<JsonCountryData>(apiResponse);
// after here you can access the "Success" and "Message" properties on the "JsonData" object
There's nothing special about the "message" property in the JSON response. You would access it exactly the same way that you already access the "data" property.
I had this problem few days ago, And thought that I'd found the solution which was
setting lazy loading : false.
but my problem to retrieve the data persisted.
Using fiddler, or a front-end app I can't retrieve the data and as result I have only has values like : $ref=6
I think it is some kind of general setting problem, so I'm going to give some information here.
controller:
[AllowAnonymous]
[HttpGet]
[Route("GetQuestionsByTestId/{id}")]
public ICollection<Question> GetQuestionsByTestId(int id)
{
return db.Questions.Where(t => t.TestId == id)
.Include(a => a.Answers)
.Include(q=>q.Test)
.Include(q=>q.Test.TestType)
.ToList();
}
identityModels:
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
this.Configuration.LazyLoadingEnabled = false; //false for Lazy Loading Off
this.Configuration.ProxyCreationEnabled = false;
}
WebApiConfig:
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);
question Model:
[Table("Question")]
public class Question
{
public Question()
{
Answers = new HashSet<Answer>();
}
[Key]
public int QuestionId { get; set; }
[Required]
public string Name { get; set; }
public string Comment { get; set; }
public int Difficulty { get; set; }
public byte Repeat { get; set; } // 0 - 255
public bool IsLearned { get; set; }
public string QuestionNumber { get; set; }
public virtual ICollection<Answer> Answers { get; set; }
[ForeignKey("Chapter")]
public int ChapterId { get; set; }
public Chapter Chapter { get; set; }
[ForeignKey("Test")]
public int TestId { get; set; }
public Test Test { get; set; }
}
my return retrieved with chrome NETWORK: this is where my problem is:
[{$id: "1", QuestionId: 5, Name: "11", Comment: null, Difficulty: 0, Repeat: 0,
IsLearned: false,…},…]
0: {$id: "1", QuestionId: 5, Name: "11", Comment: null, Difficulty: 0, Repeat: 0,
IsLearned: false,…}
1: {$ref: "6"}
second object is not visible, there is only this: $ref:"6"
Please help, losing hope here.
I'm guessing here that you're using Entity Framework to store and retrieve data. Realistically you don't want to be returning data/entities straight from your database, you probably want to map your data into a set of classes called Data Transfer Objects (DTO).
You can do this manually or using a tool such as AutoMapper.
Manually you would do something like this
Create a DTO class:
public class QuestionDTO
{
public int QuestionId { get; set; }
public string Name { get; set; }
public string Comment { get; set; }
public int Difficulty { get; set; }
public byte Repeat { get; set; } // 0 - 255
public bool IsLearned { get; set; }
public string QuestionNumber { get; set; }
}
Change controller method:
[AllowAnonymous]
[HttpGet]
[Route("GetQuestionsByTestId/{id}")]
public IHttpActionResult GetQuestionsByTestId(int id)
{
var questions = db.Questions.Where(t => t.TestId == id)
.Include(a => a.Answers)
.Include(q => q.Test)
.Include(q => q.Test.TestType)
.ToList();
var questionDTOs = new List<QuestionDTO>();
foreach (var question in questions)
{
questionDTOs.Add(new QuestionDTO
{
QuestionId = question.QuestionId,
Name = question.Name,
Comment = question.Comment,
Difficulty = question.Difficulty,
Repeat = question.Repeat,
IsLearned = question.IsLearned,
QuestionNumber = question.QuestionNumber
});
}
return Ok(questionDTOs);
}
(I have changed the return type so that you can use the Ok method that will return a 200 message or if needed return other status codes such as 400 using BadRequest() etc)
Using DTOs allows you to control exactly what data is returned and you don't have to worry about changing things like Lazy loading or proxy creation
I want to receive json formatted posted data to my controller. Actually it's used for paypal payment webhook call issue. I already attached a json data example. Please advice me "FormCollection" is good idea to access that json or whats the best practice for this situation?
Json:
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
Controller:
[HttpPost]
public JsonResult ReceiveData(FormCollection data)
{
using (var ctx = new db_mydb())
{
}
return Json("ok");
}
Since that data being received is structured and comming in as JSON you should create strongly typed model(s) to store the data.
public class Menuitem {
public string value { get; set; }
public string onclick { get; set; }
}
public class Popup {
public IList<Menuitem> menuitem { get; set; }
}
public class Menu {
public string id { get; set; }
public string value { get; set; }
public Popup popup { get; set; }
}
public class PaypalWebhookModel {
public Menu menu { get; set; }
}
Action should be updated to reflect the desired model.
[HttpPost]
public JsonResult ReceiveData([FromBody]PaypalWebhookModel data) {
using (var ctx = new db_mydb()) {
//...
}
return Json("ok");
}
I have a simple object model
public class License
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string CreationUserId { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string LastModifiedUserId { get; set; }
public string LicenseName { get; set; }
public LicenseType LicenseType { get; set; }
public State State { get; set; }
public DateTime DateIssued { get; set; }
public int ValidFor { get; set; }
}
public class State
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string CreationUserId { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string LastModifiedUserId { get; set; }
[StringLength(2)]
[Required]
public string Name { get; set; }
[Display(Name = "Long Name")]
[Required, StringLength(25)]
public string LongName { get; set; }
}
public class LicenseType
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string CreationUserId { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string LastModifiedUserId { get; set; }
[StringLength(100), Required]
public string Description { get; set; }
}
I am using the hot towel template breeze, durandal, knockout.
I have a simple add view model
var _licenseAdded = false;
var vm = {
states: ko.observableArray(context.states),
licenseTypes: ko.observableArray(context.licenseTypes),
viewAttached: function () {
var self = this;
$('input[name^="date"]').datepicker();
$('#validFor').spinner({
min: 365,
max: 3650,
step: 30
});
log('add Attached', null, true);
},
activate: function () {
var self = this;
self.original = context.manager.createEntity('License', { licenseName: 'Testing321', dateIssued: moment().format('L') }, null);
log('add Activated', null, true);
},
canDeactivate: function () {
if (_licenseAdded === false) {
return app.showMessage('Are you sure you want to leave this page?', 'Navigate', ['Yes', 'No']);
} else {
return true;
}
},
saveChanges: function () {
$.when(context.saveNewLicense()).done(function () {
_licenseAdded = true;
});
router.navigateTo('home');
},
original: undefined
};
return vm;
And here is my add.html, everything binds up fine and works beautifully until saving.
When I call saveChanges the saveBundle sent to the controller has no navigation properties attached that allow for the correct State and LicenseType to be stored I only get:
saveBundle {
"entities": [
{
"Id": -1,
"CreationUserId": null,
"LastModifiedUserId": null,
"LicenseName": "new for testing",
"DateIssued": "2013-03-11T04:00:00Z",
"ValidFor": 0,
"entityAspect": {
"entityTypeName": "License:#Volt.Telecom.Licensing.Models",
"entityState": "Added",
"originalValuesMap": {},
"autoGeneratedKey": {
"propertyName": "Id",
"autoGeneratedKeyType": "Identity"
}
}
}
],
"saveOptions": {
"allowConcurrentSaves": false
}
}
Don't think I can get much more vanilla than this. Why might this occur? When I am debugging on the client the state and licenseType navigationProperties are all correct and with the correct values.
I think the issue is that your EF model uses 'Independent Associations' instead of 'Foreign Key Assocations' (foreign key associations are the EF default). We do need to do a better job of documenting this assumption.
The reason for this requirement, which can be bypassed but with a substantial loss of functionality, is that the existence of foreign keys on the client is what allows breeze to automatically fix up relationships between entities that might be queried separately.
See the following MSDN article for more background: foreign-keys-in-the-entity-framework
I received a nice implementation form mapping the key (ID) of a nested child (see here: Mapping a model into a dto and 'include' only the key of child element) but here I search for a slightly different solution as explained below.
I have the following Project model:
public class Project
{
[Key]
public int ProjectID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<Screenshot> Screenshots { get; set; }
}
And I have the following Screenshot model:
public class Screenshot
{
[Key]
public int ScreenshotID { get; set; }
public string ScreenshotName { get; set; }
public byte[] ScreenshotContent { get; set; }
public string ScreenshotContentType { get; set; }
}
As you can see, each project have some screenshots attached. In the following function, I would like to retrieve some projects and only the pair ScreenshotID + ScreenshotName of the corresponding screenshots.
public SearchResultDTO<ProjectDTO> GetProjects(SearchParametersProjectDTO dto)
{
...
var resultDTO = new SearchResultDTO<ProjectDTO>
{
Entities = Mapper.Map<IEnumerable<Project>, IEnumerable<ProjectDTO>>(projects.ToList()),
TotalItems = projects.Count()
};
return resultDTO;
}
Here is the ProjectDTO:
[DataContract]
public class ProjectDTO : BaseDTO<ProjectDTO, Project>
{
[DataMember]
public int ProjectID { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public Dictionary<int, string> Screenshots { get; set; }
So I don't know how to map "ScreenshotID + ScreenshotName" into the Screenshots property of my DTO.
Any help is greatly appreciated.
Thanks.
You could define a mapping between Screenshot and KeyValuePair<int, string> and a mapping between Project and ProjectDTO:
Mapper
.CreateMap<Screenshot, KeyValuePair<int, string>>()
.ConvertUsing(s => new KeyValuePair<int, string>(s.ScreenshotID, s.ScreenshotName));
Mapper
.CreateMap<Project, ProjectDTO>();
and then:
var project = new Project
{
Screenshots = new[]
{
new Screenshot { ScreenshotID = 1, ScreenshotName = "name " + 1 },
new Screenshot { ScreenshotID = 2, ScreenshotName = "name " + 2 },
new Screenshot { ScreenshotID = 3, ScreenshotName = "name " + 3 },
}
};
var projectDto = Mapper.Map<Project, ProjectDTO>(project);
// at this stage the projectDto.Screenshots dictionary will contain
// the necessary information