public void DTO2BD(DTO.Supplier dtoItem, ref Supplier dbItem)
        {
            //
            if (dtoItem.supplierBanks != null)
            {
                foreach (var item in dbItem.SupplierBank.ToArray())
                {
                    if (!dtoItem.supplierBanks.Select(o => o.SupplierBankID).Contains(item.SupplierBankID))
                    {
                        dbItem.SupplierBank.Remove(item);
                    }
                }
                //map child row
                foreach (var item in dtoItem.supplierBanks)
                {
                    SupplierBank dbSupplierBank;
                    if (item.SupplierBankID <= 0)
                    {
                        dbSupplierBank = new SupplierBank();
                        dbItem.SupplierBank.Add(dbSupplierBank);
                    }
                    else
                    {
                        dbSupplierBank = dbItem.SupplierBank.FirstOrDefault(o => o.SupplierBankID == item.SupplierBankID);
                    }
                    if (dbSupplierBank != null)
                    {
                        AutoMapper.Mapper.Map <DTO.SupplierBankDTO, SupplierBank>(item, dbSupplierBank);
                    }
                }
            }

            AutoMapper.Mapper.Map <DTO.Supplier, Supplier>(dtoItem, dbItem);
            dbItem.UpdatedDate = DateTime.Now;
        }
Example #2
0
        public bool UpdateData(int id, ref object dtoItem, int iRequesterID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.Supplier dtoSupplier = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.Supplier>();
            try
            {
                using (SupplierMngEntities context = CreateContext())
                {
                    Supplier dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new Supplier();
                        context.Supplier.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Supplier.FirstOrDefault(o => o.SupplierID == id);
                        dtoSupplier.UpdatedBy = iRequesterID;
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Supplier not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoSupplier.ConcurrencyFlag_String)))
                        {
                            throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        converter.DTO2BD(dtoSupplier, ref dbItem);

                        context.SupplierBank.Local.Where(o => o.Supplier == null).ToList().ForEach(o => context.SupplierBank.Remove(o));

                        context.SaveChanges();

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

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Example #3
0
 public void customSupplier(DTO.Supplier sup)
 {
     DAL.DALConnect.Instance.MyExecuteNonQuery("update suppliers set name = N'" + sup.Name + "', address = N'" + sup.Address + "',phone = " + sup.Phone + " where sid =" + sup.Id, CommandType.Text);
 }
Example #4
0
 public void insertSupplier(DTO.Supplier sup)
 {
     DAL.DALConnect.Instance.MyExecuteNonQuery("insert into suppliers(name,address,phone) values(N'" + sup.Name + "',N'" + sup.Address + "'," + sup.Phone + ")", CommandType.Text);
 }
 public DTO.Supplier DB2DTO_Supplier(SupplierMng_Supplier_View dbItem)
 {
     DTO.Supplier dtoItem = AutoMapper.Mapper.Map <SupplierMng_Supplier_View, DTO.Supplier>(dbItem);
     dtoItem.ConcurrencyFlag_String = Convert.ToBase64String(dtoItem.ConcurrencyFlag);
     return(dtoItem);
 }