// удаляет награду человека public void DeletePeopleAward(int id) { try { PeopleAwards award = dbContext.ListPeopleAwards.Find(id); dbContext.ListPeopleAwards.Remove(award); dbContext.SaveChanges(); } catch (Exception ex) { Logger.LogException(new Exception(String.Format("Ошибка:\n{0}\n{1}\n{2}", ex.Message, ex.StackTrace, ex.InnerException.StackTrace))); throw; } }
// сохраняет награду человека public void SavePeopleAward(int peopleID, int awardID) { PeopleAwards savePeopleAward = new PeopleAwards(); savePeopleAward.PeopleID = peopleID; savePeopleAward.AwardID = awardID; dbContext.ListPeopleAwards.Add(savePeopleAward); try { dbContext.SaveChanges(); } catch (Exception ex) { Logger.LogException(new Exception(String.Format("Ошибка:\n{0}\n{1}\n{2}", ex.Message, ex.StackTrace, ex.InnerException.StackTrace))); throw ex; } }
// сохраняет награду человека public int SavePeopleAward(int peopleID, int awardID) { PeopleAwards savePeopleAward = new PeopleAwards(); savePeopleAward.PeopleID = peopleID; savePeopleAward.AwardID = awardID; dbContext.ListPeopleAwards.Add(savePeopleAward); try { dbContext.SaveChanges(); return(dbContext.ListPeopleAwards.ToList().FirstOrDefault(c => c.AwardID == awardID && c.PeopleID == peopleID).Id); } catch (Exception ex) { Logger.LogException(new Exception(String.Format("Ошибка:\n{0}\n{1}\n{2}", ex.Message, ex.StackTrace, ex.InnerException.StackTrace))); throw ex; } }
// маппит из Model в Entity public void PeopleModelMapToPeoples(PeopleViewModel source, ref People dest, bool isPeoplePart = false) { try { dest.Id = source.Id; dest.FirstName = source.FirstName; dest.LastName = source.LastName; dest.BirthDate = source.BirthDate; if (source.PhotoPeople == null) { dest.PhotoPeople = null; } else { dest.PhotoPeople = UtilHelper.HttpPostedFileBaseToByte(source.PhotoPeople); } if (source.PhotoMIMEType == null || source.PhotoPeople == null) { dest.PhotoMIMEType = ""; } else { dest.PhotoMIMEType = source.PhotoMIMEType; } List <PeopleAwards> lst = new List <PeopleAwards>(); if (isPeoplePart) { dest.PeopleAwards = lst; return; } List <ListPeopleAwardsViewModel> entList = source.PeopleAwards.ToList(); PeopleAwards peopleAward; foreach (var item in entList) { peopleAward = new PeopleAwards(); peopleAward.Id = item.Id; peopleAward.PeopleID = item.PeopleID; peopleAward.AwardID = item.AwardID; Awards award = new Awards(); award.Id = item.Award.Id; award.NameAward = item.Award.NameAward; award.DescriptionAward = item.Award.DescriptionAward; if (item.Award.PhotoAward != null) { award.PhotoAward = UtilHelper.HttpPostedFileBaseToByte(item.Award.PhotoAward); } award.PhotoMIMEType = item.Award.PhotoMIMEType; peopleAward.Award = award; lst.Add(peopleAward); } dest.PeopleAwards = lst; } catch (Exception ex) { Logger.LogException(new Exception(String.Format("Ошибка:\n{0}\n{1}\n{2}", ex.Message, ex.StackTrace, ex.InnerException.StackTrace))); throw ex; } }