public void Update(CharityRecordUiModel model) { try { using (CharityEntities entities = new CharityEntities()) { CharityRecord charityRecord = new CharityRecord(); var record = entities.CharityRecords.Include(x => x.FileDetails).Where(x => x.Id == model.id).FirstOrDefault(); record.Title = model.Title; record.Description = model.Description; record.Charity = model.Charity; record.PlayItForward = model.PlayItFwd; record.UserId = model.UserId; record.Currency = model.Currency; foreach (var item in model.FileDetails) { FileDetail detailsobj = new FileDetail(); detailsobj.FileInfo = item.FileInfo; detailsobj.FileName = item.FileName; detailsobj.CharityId = item.CharityId; entities.FileDetails.Add(detailsobj); } entities.SaveChanges(); } } catch (Exception ex) { throw; } }
public void Write(CharityRecordUiModel record) { try { using (CharityEntities entities = new CharityEntities()) { CharityRecord charityRecord = new CharityRecord(); charityRecord.Title = record.Title; charityRecord.Description = record.Description; charityRecord.Charity = record.Charity; charityRecord.PlayItForward = record.PlayItFwd; charityRecord.UserId = record.UserId; charityRecord.Currency = record.Currency; charityRecord.Status = 0; entities.CharityRecords.Add(charityRecord); foreach (var item in record.FileDetails) { FileDetail detailsobj = new FileDetail(); detailsobj.FileInfo = item.FileInfo; detailsobj.FileName = item.FileName; detailsobj.CharityId = charityRecord.Id; entities.FileDetails.Add(detailsobj); } entities.SaveChanges(); } } catch (Exception ex) { throw; } }