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

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Esempio n. 2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.PaymentTerm dtoPaymentTerm = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.PaymentTerm>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                // cuong.tran: #2090 - Update Payment term module (view detail) - start
                // If Type = 4 then Method = "LC"
                if (dtoPaymentTerm.PaymentTypeID.HasValue && dtoPaymentTerm.PaymentTypeID.Value == 4)
                {
                    dtoPaymentTerm.PaymentMethod = "LC";
                }
                // Check data validation
                // Case DP_Percent
                if ("DP-PERCENT".Equals(dtoPaymentTerm.PaymentMethod))
                {
                    // Warning: Check value of DownValue
                    if (!dtoPaymentTerm.DownValue.HasValue)
                    {
                        notification.Type    = NotificationType.Error;
                        notification.Message = "Please input value DownValue!";
                        return(false);
                    }

                    // Warning: Check value DownValue larger than 100
                    if (dtoPaymentTerm.DownValue.Value > 100)
                    {
                        notification.Type    = NotificationType.Error;
                        notification.Message = "Please input value DownValue smaller than 100!";
                        return(false);
                    }
                }
                // cuong.tran: #2090 - Update Payment term module (view detail) - e n d


                using (PaymentTermMngEntities context = CreateContext())
                {
                    PaymentTerm dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new PaymentTerm();
                        context.PaymentTerm.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.PaymentTerm.FirstOrDefault(o => o.PaymentTermID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Payment Term not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2BD_PaymentTerm(dtoPaymentTerm, 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);
            }
        }
Esempio n. 3
0
 public void DTO2BD_PaymentTerm(DTO.PaymentTerm dtoItem, ref PaymentTerm dbItem)
 {
     AutoMapper.Mapper.Map <DTO.PaymentTerm, PaymentTerm>(dtoItem, dbItem);
 }