Beispiel #1
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 (PaymentTermMngEntities context = CreateContext())
                {
                    PaymentTerm dbItem = context.PaymentTerms.FirstOrDefault(o => o.PaymentTermID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Payment Term not found!";
                        return(false);
                    }
                    else
                    {
                        context.PaymentTerms.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Beispiel #2
0
        public override bool UpdateData(int id, ref DTO.PaymentTermMng.PaymentTerm dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (PaymentTermMngEntities context = CreateContext())
                {
                    PaymentTerm dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new PaymentTerm();
                        context.PaymentTerms.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.PaymentTerms.FirstOrDefault(o => o.PaymentTermID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Payment Term not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2BD_PaymentTerm(dtoItem, ref dbItem);
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.PaymentTermID, out notification).Data;

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
 public void DTO2BD_PaymentTerm(DTO.PaymentTermMng.PaymentTerm dtoItem, ref PaymentTerm dbItem)
 {
     AutoMapper.Mapper.Map <DTO.PaymentTermMng.PaymentTerm, PaymentTerm>(dtoItem, dbItem);
 }