public override bool DeleteData(int id, out DTO.Framework.Notification notification) { notification = new DTO.Framework.Notification() { Type = DTO.Framework.NotificationType.Success }; try { using (ClientPaymentMngEntities context = CreateContext()) { ClientPayment dbItem = context.ClientPayment.FirstOrDefault(o => o.ClientPaymentID == id); if (dbItem == null) { notification.Message = "payment not found!"; return(false); } else { context.ClientPayment.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = DTO.Framework.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(false); } }
public override bool UpdateData(int id, ref DTO.ClientPaymentMng.ClientPayment dtoItem, out DTO.Framework.Notification notification) { notification = new DTO.Framework.Notification() { Type = DTO.Framework.NotificationType.Success }; try { using (ClientPaymentMngEntities context = CreateContext()) { ClientPayment dbItem = null; if (id == 0) { dbItem = new ClientPayment(); context.ClientPayment.Add(dbItem); } else { dbItem = context.ClientPayment.FirstOrDefault(o => o.ClientPaymentID == id); } if (dbItem == null) { notification.Message = "payment not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String))) { throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT); } //convert dto to db converter.DTO2DB_ClientPayment(dtoItem, ref dbItem); context.SaveChanges(); dtoItem = GetData(dbItem.ClientPaymentID, out notification); return(true); } } } catch (Exception ex) { notification.Type = DTO.Framework.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(false); } }
public void DTO2DB_ClientPayment(DTO.ClientPaymentMng.ClientPayment dtoItem, ref ClientPayment dbItem) { List <ClientPaymentDetail> paymentdetail_tobedeleted = new List <ClientPaymentDetail>(); if (dtoItem.ClientPaymentDetails != null) { //CHECK foreach (var dbDetail in dbItem.ClientPaymentDetail.Where(o => !dtoItem.ClientPaymentDetails.Select(s => s.ClientPaymentDetailID).Contains(o.ClientPaymentDetailID))) { paymentdetail_tobedeleted.Add(dbDetail); } foreach (var dbDetail in paymentdetail_tobedeleted) { dbItem.ClientPaymentDetail.Remove(dbDetail); } //MAP foreach (var dtoDetail in dtoItem.ClientPaymentDetails) { ClientPaymentDetail dbDetail; if (dtoDetail.ClientPaymentDetailID < 0) { dbDetail = new ClientPaymentDetail(); dbItem.ClientPaymentDetail.Add(dbDetail); } else { dbDetail = dbItem.ClientPaymentDetail.FirstOrDefault(o => o.ClientPaymentDetailID == dtoDetail.ClientPaymentDetailID); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.ClientPaymentMng.ClientPaymentDetail, ClientPaymentDetail>(dtoDetail, dbDetail); dbDetail.PaymentDate = dtoDetail.PaymentDate.ConvertStringToDateTime(); dbDetail.ReceivedDate = dtoDetail.ReceivedDate.ConvertStringToDateTime(); } } } AutoMapper.Mapper.Map <DTO.ClientPaymentMng.ClientPayment, ClientPayment>(dtoItem, dbItem); if (dtoItem.ClientPaymentID < 0) { dbItem.CreatedDate = DateTime.Now; dbItem.CreatedBy = dtoItem.UpdatedBy; } dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = dtoItem.UpdatedBy; dbItem.PaymentDate = dtoItem.PaymentDate.ConvertStringToDateTime(); }