예제 #1
0
 public override bool DeleteData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (FactoryWarehouseEntities context = CreateContext())
         {
             var dbItem = context.FactoryWarehouse.Where(o => o.FactoryWarehouseID == id).FirstOrDefault();
             context.FactoryWarehouse.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);
     }
 }
예제 #2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.FactoryWarehouse dtofWarehouse = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryWarehouse>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            List <DTO.FactoryWarehouse> FactoryWarehouseDTOs = new List <DTO.FactoryWarehouse>();

            try
            {
                using (FactoryWarehouseEntities context = CreateContext())
                {
                    FactoryWarehouse dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactoryWarehouse();
                        context.FactoryWarehouse.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FactoryWarehouse.FirstOrDefault(o => o.FactoryWarehouseID == id);
                    }

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

                        //if (dtofWarehouse.FactoryWarehouseUD != "")
                        //{
                        //    var FactoryWarehouseBDs = context.FactoryWarehouse_FactoryWarehouse_View.Where(o => o.FactoryWarehouseID != id).ToList();
                        //    FactoryWarehouseDTOs = converter.DB2DTO_WarehouseList(FactoryWarehouseBDs);
                        //    foreach (DTO.FactoryWarehouse WarehouseData in FactoryWarehouseDTOs)
                        //    {
                        //        if (dtofWarehouse.FactoryWarehouseUD != null)
                        //        {
                        //            if (dtofWarehouse.FactoryWarehouseUD == WarehouseData.FactoryWarehouseUD)
                        //            {
                        //                throw new Exception("This Warehouse Code already exist in the system!");
                        //            }
                        //        }
                        //    }
                        //}

                        dtofWarehouse.CompanyID = fwFactory.GetCompanyID(userId);

                        converter.DTO2DB(dtofWarehouse, ref dbItem);
                        //remove orphan item

                        context.FactoryWarehousePallet.Local.Where(o => o.FactoryWarehouse == null).ToList().ForEach(o => context.FactoryWarehousePallet.Remove(o));

                        dbItem.UpdatedDate = DateTime.Now;
                        dbItem.UpdatedBy   = userId;

                        context.SaveChanges();

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

                        return(true);
                    }
                }
            }

            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }