コード例 #1
0
        public override bool UpdateData(int id, ref DTO.FactoryPaymentMng.FactoryPayment dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryPaymentMngEntities context = CreateContext())
                {
                    FactoryPayment dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactoryPayment();
                        context.FactoryPayment.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FactoryPayment.FirstOrDefault(o => o.FactoryPaymentID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "FactoryPayment 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);
                        }

                        converter.DTO2BD_FactoryPayment(dtoItem, ref dbItem);
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.FactoryPaymentID, out notification).FactoryPayment;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
コード例 #2
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success, Message = "Delete success"
            };
            try
            {
                using (FactoryPaymentMngEntities context = CreateContext())
                {
                    FactoryPayment dbItem = context.FactoryPayment.FirstOrDefault(o => o.FactoryPaymentID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "FactoryPayment not found!";
                        return(false);
                    }
                    else
                    {
                        context.FactoryPayment.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
コード例 #3
0
 public void DTO2BD_FactoryPayment(DTO.FactoryPaymentMng.FactoryPayment dtoItem, ref FactoryPayment dbItem)
 {
     AutoMapper.Mapper.Map <DTO.FactoryPaymentMng.FactoryPayment, FactoryPayment>(dtoItem, dbItem);
     dbItem.PaymentDate = dtoItem.PaymentDate.ConvertStringToDateTime();
     if (dbItem.FactoryPaymentID > 0)
     {
         dbItem.UpdatedDate = DateTime.Now;
         dbItem.UpdatedBy   = dtoItem.UpdatedBy;
     }
     else
     {
         dbItem.CreatedDate = DateTime.Now;
         dbItem.CreatedBy   = dtoItem.UpdatedBy;
     }
 }