// POST odata/Project public async Task <IHttpActionResult> Post(Delta <Project> patch) { var project = patch.GetEntity(); // Don't allow the user to set these fields / coni2k - 29 Jul. '17 // TODO Use ForbiddenFieldsValidator?: Currently breeze doesn't allow to post custom (delta) entity // TODO Or use DTO?: Needs a different metadata than the context, which can be overkill project.Id = 0; //project.UserId = 0; project.RatingCount = 0; project.CreatedOn = DateTime.UtcNow; project.ModifiedOn = DateTime.UtcNow; project.DeletedOn = null; // Owner check: Entity must belong to the current user var currentUserId = User.Identity.GetUserId <int>(); if (currentUserId != project.UserId) { return(StatusCode(HttpStatusCode.Forbidden)); } await _projectManager.AddProjectAsync(project); return(Created(project)); }
private async void SaveProject(object projectObject) { ProjectViewModel project = projectObject as ProjectViewModel; if (project != null && project.IsValid) { project.Trim(); await projectManager.AddProjectAsync(project.Project); Projects.Add(project); Back(); } else { //show nessage about problem Services.IMessageService MessageService = DependencyService.Get <Services.IMessageService>(); await MessageService.ShowAsync("Please fill empty fields"); } }
// POST odata/Project public async Task <IHttpActionResult> Post(Delta <Project> patch) { var project = patch.GetEntity(); // Don't allow the user to set these fields / coni2k - 29 Jul. '17 // TODO Use ForbiddenFieldsValidator?: Currently breeze doesn't allow to post custom (delta) entity // TODO Or use DTO?: Needs a different metadata than the context, which can be overkill project.Id = 0; //project.UserId = 0; project.RatingCount = 0; project.CreatedOn = DateTime.UtcNow; project.ModifiedOn = DateTime.UtcNow; project.DeletedOn = null; // Owner check: Entity must belong to the current user var currentUserId = User.Identity.GetUserId <int>(); if (currentUserId != project.UserId) { return(StatusCode(HttpStatusCode.Forbidden)); } try { await _projectManager.AddProjectAsync(project); } catch (DbUpdateException) { // Unique key exception if (await _projectManager.GetProjectSet(null, false).AnyAsync(item => item.Key == project.Key)) { return(new UniqueKeyConflictResult(Request, nameof(Project.Key), project.Key)); } throw; } return(Created(project)); }