コード例 #1
0
 public void DTO2DB_SupplierPaymentTerm(DTO.SupplierPaymentTermDto dtoItem, ref SupplierPaymentTerm dbItem)
 {
     AutoMapper.Mapper.Map <DTO.SupplierPaymentTermDto, SupplierPaymentTerm>(dtoItem, dbItem);
 }
コード例 #2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            notification = new Notification()
            {
                Type = NotificationType.Success
            };
            DTO.SupplierPaymentTermDto dtoItems = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SupplierPaymentTermDto>();
            try
            {
                using (var context = CreatContex())
                {
                    SupplierPaymentTerm dbItem;
                    if (id == 0)
                    {
                        dbItem = new SupplierPaymentTerm();
                        context.SupplierPaymentTerm.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.SupplierPaymentTerm.Where(o => o.SupplierPaymentTermID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "Data Not found !";
                        return(false);
                    }
                    else
                    {
                        var    SupplierData = converter.DB2DTO_SeachSupplierPaymentTerm(context.SupplierPaymentTermMng_SupplierPaymentTerm_SearchView.Where(o => o.SupplierPaymentTermID != id).ToList());
                        string upperSupplierPaymentTermNM = dtoItems.SupplierPaymentTermNM.ToUpper().Trim();
                        while (upperSupplierPaymentTermNM.IndexOf(" ") >= 0)
                        {
                            upperSupplierPaymentTermNM = upperSupplierPaymentTermNM.Replace(" ", "");
                        }
                        for (int i = 0; i < SupplierData.Count; i++)
                        {
                            string upperSupplierPaymentTermNMList = SupplierData[i].SupplierPaymentTermNM.ToUpper().Trim();
                            while (upperSupplierPaymentTermNMList.IndexOf(" ") >= 0)
                            {
                                upperSupplierPaymentTermNMList = upperSupplierPaymentTermNMList.Replace(" ", "");
                            }
                            if (upperSupplierPaymentTermNM == upperSupplierPaymentTermNMList)
                            {
                                throw new Exception("Supplier Payment Term Name already exists");
                            }
                        }
                        converter.DTO2DB_SupplierPaymentTerm(dtoItems, ref dbItem);
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.SupplierPaymentTermID, out notification).Data;
                        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);
            }
        }