public async Task <IActionResult> PutCommentReply(int id, CommentReply commentReply) { if (id != commentReply.CommentReplyId) { return(BadRequest()); } _context.Entry(commentReply).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentReplyExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
internal static void UpdateFromModel(this NewsRelease dbPost, Models.Post post, HubDbContext dbContext) { dbContext.Entry(dbPost).CurrentValues.SetValues(post); dbPost.ReleaseType = Enum.Parse <ReleaseType>(post.Kind); var newsReleaseLanguage = dbPost.NewsReleaseLanguage.FirstOrDefault(); if (newsReleaseLanguage == null) { newsReleaseLanguage = new NewsReleaseLanguage() { LanguageId = Language.enCA }; dbPost.NewsReleaseLanguage.Add(newsReleaseLanguage); } newsReleaseLanguage.Location = post.Location; newsReleaseLanguage.Summary = post.Summary; dbPost.Ministry = dbContext.Ministry.FirstOrDefault(m => m.Key == post.LeadMinistryKey); if (post.MinistryKeys != null) { dbContext.NewsReleaseMinistry.RemoveRange(dbPost.NewsReleaseMinistry.Where(m => !post.MinistryKeys.Contains(m.Ministry.Key))); foreach (var newMinistry in post.MinistryKeys.Where(sh => !dbPost.NewsReleaseMinistry.Any(m => m.Ministry.Key == sh))) { dbPost.NewsReleaseMinistry.Add(new NewsReleaseMinistry { Release = dbPost, Ministry = dbContext.Ministry.Single(m => m.Key == newMinistry) }); } } dbPost.Timestamp = DateTimeOffset.Now; }
internal static void UpdateFromModel(this Activity dbActivity, Models.Activity activity, HubDbContext dbContext) { dbContext.Entry(dbActivity).CurrentValues.SetValues(activity); dbActivity.ContactMinistry = dbContext.Ministry.FirstOrDefault(m => m.Abbreviation == activity.ContactMinistryAbbreviation); if (activity.MinistriesSharedWith != null) { // This will also remove the unchecked ministries from dbActivity.ActivitySharedWith when the changed in the context are saved dbContext.ActivitySharedWith.RemoveRange(dbActivity.ActivitySharedWith.Where(m => !activity.MinistriesSharedWith.Contains(m.Ministry.Key))); foreach (var newMinistry in activity.MinistriesSharedWith.Where(sh => !dbActivity.ActivitySharedWith.Any(m => m.Ministry.Key == sh))) { dbActivity.ActivitySharedWith.Add(new ActivitySharedWith { Activity = dbActivity, Ministry = dbContext.Ministry.Single(m => m.Key == newMinistry) }); } } if (activity.Categories != null) { dbContext.ActivityCategories.RemoveRange(dbActivity.ActivityCategories.Where(ac => !activity.Categories.Contains(ac.Category.Name))); foreach (var newCategory in activity.Categories.Where(sh => !dbActivity.ActivityCategories.Any(ac => ac.Category.Name == sh))) { dbActivity.ActivityCategories.Add(new ActivityCategories { Activity = dbActivity, Category = dbContext.Category.Single(m => m.Name == newCategory) }); } } dbActivity.LastUpdatedDateTime = DateTime.Now; }
public async Task <IActionResult> PutUserPayment(int id, UserPayment userPayment) { if (id != userPayment.UserPaymentId) { return(BadRequest()); } _context.Entry(userPayment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserPaymentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutModuleCategory(int id, ModuleCategory moduleCategory) { if (id != moduleCategory.ModuleCategoryId) { return(BadRequest()); } _context.Entry(moduleCategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ModuleCategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutEventRego(int id, EventRego eventRego) { if (id != eventRego.EventRegoId) { return(BadRequest()); } _context.Entry(eventRego).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventRegoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutFacility(int id, Facility facility) { if (id != facility.FacilityId) { return(BadRequest()); } _context.Entry(facility).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FacilityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult AddSocialMediaPost(Models.SocialMediaPost socialMediaPost) { try { if (socialMediaPost.Id != Guid.Empty) { throw new ValidationException("Invalid parameter (id)"); } var dbPost = new SocialMediaPost { IsActive = true }; socialMediaPost.Id = Guid.NewGuid(); socialMediaPost.Timestamp = DateTime.Now; dbContext.Entry(dbPost).CurrentValues.SetValues(socialMediaPost); dbContext.SocialMediaPost.Add(dbPost); dbContext.SaveChanges(); return(CreatedAtRoute("GetSocialMediaPost", new { id = dbPost.Id }, mapper.Map <Models.SocialMediaPost>(dbPost))); } catch (Exception ex) { return(BadRequest("Failed to create social media post", ex)); } }
public IActionResult AddPostLog([FromBody] Models.PostLog logEntry) { try { var dbPost = dbContext.NewsRelease.Include(p => p.NewsReleaseLog).FirstOrDefault(p => p.Key == logEntry.PostKey); var dbPostLog = new NewsReleaseLog { DateTime = DateTimeOffset.Now }; dbContext.Entry(dbPostLog).CurrentValues.SetValues(logEntry); dbPost.NewsReleaseLog.Add(dbPostLog); dbContext.SaveChanges(); return(CreatedAtRoute("GetPostLogs", new { key = logEntry.PostKey }, mapper.Map <Models.PostLog>(dbPostLog))); } catch (Exception ex) { return(BadRequest("Failed to save a new post log entry", ex)); } }