Exemplo n.º 1
0
        public object UpdateData(int userID, Hashtable filters, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            try
            {
                Framework.DAL.DataFactory fwFactory = new Framework.DAL.DataFactory();

                int id = (filters.ContainsKey("id") && filters["id"] != null && !string.IsNullOrEmpty(filters["id"].ToString())) ? Convert.ToInt32(filters["id"].ToString()) : 0;
                List <DTO.ProductionIssueData> dataItem = filters.ContainsKey("view") && filters["view"] != null && !string.IsNullOrEmpty(filters["view"].ToString().Trim()) ? ((Newtonsoft.Json.Linq.JArray)filters["view"]).ToObject <List <DTO.ProductionIssueData> >() : null;

                using (var context = CreateContext())
                {
                    if (dataItem == null || dataItem.Count == 0)
                    {
                        notification.Type    = Library.DTO.NotificationType.Error;
                        notification.Message = "Can not update data with array is null!";

                        return(null);
                    }

                    foreach (DTO.ProductionIssueData dtoItem in dataItem)
                    {
                        DeliveryNote dbItem = new DeliveryNote();
                        context.DeliveryNote.Add(dbItem);

                        converter.DTO2DB_DeliveryNote(dtoItem, ref dbItem);

                        dbItem.DeliveryNoteDate   = DateTime.Now;
                        dbItem.CompanyID          = fwFactory.GetCompanyID(userID);
                        dbItem.UpdatedBy          = userID;
                        dbItem.UpdatedDate        = DateTime.Now;
                        dbItem.ViewName           = "Warehouse2Team";
                        dbItem.ToProductionTeamID = dtoItem.ToProductionTeamID;

                        context.SaveChanges();
                        context.DeliveryNoteMng_function_GenerateDeliveryNoteUD(dbItem.DeliveryNoteID, dbItem.CompanyID, dbItem.DeliveryNoteDate.Value.Year, dbItem.DeliveryNoteDate.Value.Month);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
            }

            return(null);
        }
Exemplo n.º 2
0
        public void DTO2DB_DeliveryNote(DTO.ProductionIssueData dtoItem, ref DeliveryNote dbItem)
        {
            AutoMapper.Mapper.Map <DTO.ProductionIssueData, DeliveryNote>(dtoItem, dbItem);

            foreach (var dtoDetail in dtoItem.ProductionIssueDetail)
            {
                if (dtoDetail.IssueQuantity != null)
                {
                    DeliveryNoteDetail dbItemDetail;
                    dbItemDetail = new DeliveryNoteDetail();

                    dbItem.DeliveryNoteDetail.Add(dbItemDetail);

                    dbItemDetail.FromFactoryWarehouseID = dtoDetail.FromFactoryWarehouseID;
                    dbItemDetail.Qty              = dtoDetail.IssueQuantity;
                    dbItemDetail.WorkOrderID      = dtoItem.WorkOrderID;
                    dbItemDetail.BOMID            = dtoItem.BOMID;
                    dbItemDetail.ProductionItemID = dtoDetail.ProductionItemID;
                }
            }
        }