Exemplo n.º 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 (FactoryStockReceiptEntities context = CreateContext())
         {
             var dbItem = context.FactoryStockReceipt.Where(o => o.FactoryStockReceiptID == id).FirstOrDefault();
             context.FactoryStockReceipt.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);
     }
 }
Exemplo n.º 2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.FactoryStockReceipt dtoFactoryStockReceipt = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryStockReceipt>();
            dtoFactoryStockReceipt.UpdatedBy = userId;
            Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory();
            try
            {
                using (FactoryStockReceiptEntities context = CreateContext())
                {
                    FactoryStockReceipt dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactoryStockReceipt();
                        context.FactoryStockReceipt.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FactoryStockReceipt.Where(o => o.FactoryStockReceiptID == id).FirstOrDefault();
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //
                        if (!dtoFactoryStockReceipt.FactoryID.HasValue) // 2 : Export
                        {
                            throw new Exception("Factory is empty. You should fill-in factory");
                        }
                        //check permission on factory
                        if (fwFactory.CheckFactoryPermission(userId, dtoFactoryStockReceipt.FactoryID.Value) == 0)
                        {
                            throw new Exception("You do not have access permission on this factory");
                        }

                        //validate quantity
                        if (dtoFactoryStockReceipt.ReceiptTypeID == 1) //import
                        {
                            ValidateQntImport(dtoFactoryStockReceipt);
                        }
                        else if (dtoFactoryStockReceipt.ReceiptTypeID == 2)  //export
                        {
                            ValidateQntExport(dtoFactoryStockReceipt);
                        }

                        //convert dto to db
                        converter.DTO2DB_FactoryStockReceipt(dtoFactoryStockReceipt, ref dbItem);
                        //remove orphan item
                        context.FactoryStockReceiptDetail.Local.Where(o => o.FactoryStockReceipt == null).ToList().ForEach(o => context.FactoryStockReceiptDetail.Remove(o));
                        //save data
                        context.SaveChanges();
                        //update receipt no
                        context.FactoryStockReceiptMng_function_GenerateReceipNo(dbItem.FactoryStockReceiptID, dbItem.ReceiptTypeID);
                        //get return data
                        dtoItem = GetData(userId, dbItem.FactoryStockReceiptID, 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);
            }
        }