コード例 #1
0
        public IHttpActionResult Update(int id, DTO.FactoryOrderMng.FactoryOrder dtoItem)
        {
            Library.DTO.Notification notification;

            // authentication
            Module.Framework.BLL fwBll = new Module.Framework.BLL();
            if (id > 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanUpdate))
            {
                // edit case
                return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED)));
            }
            else if (id == 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanCreate))
            {
                // create new case
                return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED)));
            }

            // validation
            if (!Helper.CommonHelper.ValidateDTO <DTO.FactoryOrderMng.FactoryOrder>(dtoItem, out notification))
            {
                return(Ok(new Library.DTO.ReturnData <DTO.FactoryOrderMng.FactoryOrder>()
                {
                    Data = dtoItem, Message = notification
                }));
            }

            // continue processing
            BLL.FactoryOrderMng bll = new BLL.FactoryOrderMng();
            bll.UpdateData(id, ref dtoItem, ControllerContext.GetAuthUserId(), out notification);

            return(Ok(new Library.DTO.ReturnData <DTO.FactoryOrderMng.FactoryOrder>()
            {
                Data = dtoItem, Message = notification
            }));
        }
コード例 #2
0
        public DTO.FactoryOrderMng.FactoryOrder DB2DTO_FactoryOrder(FactoryOrderMng_FactoryOrder_View dbItem)
        {
            DTO.FactoryOrderMng.FactoryOrder dtoItem = AutoMapper.Mapper.Map <FactoryOrderMng_FactoryOrder_View, DTO.FactoryOrderMng.FactoryOrder>(dbItem);

            /*
             *  FORMAT FIELDS DATETIME
             */
            if (dbItem.ConcurrencyFlag != null)
            {
                dtoItem.ConcurrencyFlag_String = Convert.ToBase64String(dbItem.ConcurrencyFlag);
            }

            if (dbItem.OrderDate.HasValue)
            {
                dtoItem.OrderDateFormated = dbItem.OrderDate.Value.ToString("dd/MM/yyyy");
            }

            if (dbItem.LDS1.HasValue)
            {
                dtoItem.LDS1Formated = dbItem.LDS1.Value.ToString("dd/MM/yyyy");
            }

            if (dbItem.LDS2.HasValue)
            {
                dtoItem.LDS2Formated = dbItem.LDS2.Value.ToString("dd/MM/yyyy");
            }

            if (dbItem.LDS3.HasValue)
            {
                dtoItem.LDS3Formated = dbItem.LDS3.Value.ToString("dd/MM/yyyy");
            }

            if (dbItem.LDS4.HasValue)
            {
                dtoItem.LDS4Formated = dbItem.LDS4.Value.ToString("dd/MM/yyyy");
            }

            if (dbItem.PSReceivedDate.HasValue)
            {
                dtoItem.PSReceivedDateFormated = dbItem.PSReceivedDate.Value.ToString("dd/MM/yyyy");
            }

            if (dbItem.PIReceivedDate.HasValue)
            {
                dtoItem.PIReceivedDateFormated = dbItem.PIReceivedDate.Value.ToString("dd/MM/yyyy");
            }

            if (dbItem.CreatedDate.HasValue)
            {
                dtoItem.CreatedDateFormated = dbItem.CreatedDate.Value.ToString("dd/MM/yyyy");
            }

            if (dbItem.UpdatedDate.HasValue)
            {
                dtoItem.UpdatedDateFormated = dbItem.UpdatedDate.Value.ToString("dd/MM/yyyy");
            }

            return(dtoItem);
        }
コード例 #3
0
        public IHttpActionResult Revise(int id, DTO.FactoryOrderMng.FactoryOrder dtoItem)
        {
            // authentication
            Module.Framework.BLL fwBll = new Module.Framework.BLL();
            if (!fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanReset))
            {
                return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED)));
            }

            BLL.FactoryOrderMng      bll = new BLL.FactoryOrderMng();
            Library.DTO.Notification notification;
            bll.Revise(id, ref dtoItem, ControllerContext.GetAuthUserId(), out notification);
            return(Ok(new Library.DTO.ReturnData <DTO.FactoryOrderMng.FactoryOrder>()
            {
                Data = dtoItem, Message = notification
            }));
        }
コード例 #4
0
        public void DTO2DB_FactoryOrder(DTO.FactoryOrderMng.FactoryOrder dtoItem, ref FactoryOrder dbItem)
        {
            /*
             * MAP & CHECK FactoryOrderDetail
             */
            List <FactoryOrderDetail> orderdetail_tobedeleted = new List <FactoryOrderDetail>();

            if (dtoItem.FactoryOrderDetails != null)
            {
                //CHECK
                foreach (FactoryOrderDetail dbDetail in dbItem.FactoryOrderDetail.Where(o => !dtoItem.FactoryOrderDetails.Select(s => s.FactoryOrderDetailID).Contains(o.FactoryOrderDetailID)))
                {
                    orderdetail_tobedeleted.Add(dbDetail);
                }
                foreach (FactoryOrderDetail dbDetail in orderdetail_tobedeleted)
                {
                    dbItem.FactoryOrderDetail.Remove(dbDetail);
                }
                //MAP
                foreach (DTO.FactoryOrderMng.FactoryOrderDetail dtoDetail in dtoItem.FactoryOrderDetails)
                {
                    FactoryOrderDetail dbDetail;
                    if (dtoDetail.FactoryOrderDetailID < 0)
                    {
                        dbDetail = new FactoryOrderDetail();
                        dbItem.FactoryOrderDetail.Add(dbDetail);
                    }
                    else
                    {
                        dbDetail = dbItem.FactoryOrderDetail.FirstOrDefault(o => o.FactoryOrderDetailID == dtoDetail.FactoryOrderDetailID);
                    }

                    if (dbDetail != null)
                    {
                        AutoMapper.Mapper.Map <DTO.FactoryOrderMng.FactoryOrderDetail, FactoryOrderDetail>(dtoDetail, dbDetail);
                    }
                }
            }

            /*
             * MAP & CHECK FactoryOrderSparepartDetail
             */
            List <FactoryOrderSparepartDetail> ordersparepartdetail_tobedeleted = new List <FactoryOrderSparepartDetail>();

            if (dtoItem.FactoryOrderSparepartDetails != null)
            {
                //CHECK
                foreach (var dbDetail in dbItem.FactoryOrderSparepartDetail.Where(o => !dtoItem.FactoryOrderSparepartDetails.Select(s => s.FactoryOrderSparepartDetailID).Contains(o.FactoryOrderSparepartDetailID)))
                {
                    ordersparepartdetail_tobedeleted.Add(dbDetail);
                }
                foreach (var dbDetail in ordersparepartdetail_tobedeleted)
                {
                    dbItem.FactoryOrderSparepartDetail.Remove(dbDetail);
                }
                //MAP
                foreach (var dtoDetail in dtoItem.FactoryOrderSparepartDetails)
                {
                    FactoryOrderSparepartDetail dbDetail;
                    if (dtoDetail.FactoryOrderSparepartDetailID < 0)
                    {
                        dbDetail = new FactoryOrderSparepartDetail();
                        dbItem.FactoryOrderSparepartDetail.Add(dbDetail);
                    }
                    else
                    {
                        dbDetail = dbItem.FactoryOrderSparepartDetail.FirstOrDefault(o => o.FactoryOrderSparepartDetailID == dtoDetail.FactoryOrderSparepartDetailID);
                    }

                    if (dbDetail != null)
                    {
                        AutoMapper.Mapper.Map <DTO.FactoryOrderMng.FactoryOrderSparepartDetail, FactoryOrderSparepartDetail>(dtoDetail, dbDetail);
                    }
                }
            }

            /*
             * MAP & CHECK FactoryOrderSampleDetail
             */
            List <FactoryOrderSampleDetail> ordersampedetail_tobedeleted = new List <FactoryOrderSampleDetail>();

            if (dtoItem.FactoryOrderSampleDetails != null)
            {
                //CHECK
                foreach (var dbDetail in dbItem.FactoryOrderSampleDetail.Where(o => !dtoItem.FactoryOrderSampleDetails.Select(s => s.FactoryOrderSampleDetailID).Contains(o.FactoryOrderSampleDetailID)))
                {
                    ordersampedetail_tobedeleted.Add(dbDetail);
                }
                foreach (var dbDetail in ordersampedetail_tobedeleted)
                {
                    dbItem.FactoryOrderSampleDetail.Remove(dbDetail);
                }
                //MAP
                foreach (var dtoDetail in dtoItem.FactoryOrderSampleDetails)
                {
                    FactoryOrderSampleDetail dbDetail;
                    if (dtoDetail.FactoryOrderSampleDetailID < 0)
                    {
                        dbDetail = new FactoryOrderSampleDetail();
                        dbItem.FactoryOrderSampleDetail.Add(dbDetail);
                    }
                    else
                    {
                        dbDetail = dbItem.FactoryOrderSampleDetail.FirstOrDefault(o => o.FactoryOrderSampleDetailID == dtoDetail.FactoryOrderSampleDetailID);
                    }

                    if (dbDetail != null)
                    {
                        AutoMapper.Mapper.Map <DTO.FactoryOrderMng.FactoryOrderSampleDetail, FactoryOrderSampleDetail>(dtoDetail, dbDetail);
                    }
                }
            }

            /*
             * MAP FactoryOrder History
             */
            FactoryOrderHistory       dbHistory = new FactoryOrderHistory();
            FactoryOrderHistoryDetail dbHistoryDetail;

            foreach (DTO.FactoryOrderMng.FactoryOrderDetail dtoDetail in dtoItem.FactoryOrderDetails)
            {
                dbHistoryDetail = new FactoryOrderHistoryDetail();
                AutoMapper.Mapper.Map <DTO.FactoryOrderMng.FactoryOrderDetail, FactoryOrderHistoryDetail>(dtoDetail, dbHistoryDetail);
                dbHistory.FactoryOrderHistoryDetail.Add(dbHistoryDetail);
            }
            AutoMapper.Mapper.Map <DTO.FactoryOrderMng.FactoryOrder, FactoryOrderHistory>(dtoItem, dbHistory);
            dbItem.FactoryOrderHistory.Add(dbHistory);

            /*
             * SETUP FORMATED FIELD
             */
            if (!string.IsNullOrEmpty(dtoItem.OrderDateFormated))
            {
                dtoItem.OrderDate = DateTime.ParseExact(dtoItem.OrderDateFormated, "d", new System.Globalization.CultureInfo("vi-VN"));
            }
            else
            {
                dtoItem.OrderDate = null;
            }

            if (!string.IsNullOrEmpty(dtoItem.LDS1Formated))
            {
                dtoItem.LDS1 = DateTime.ParseExact(dtoItem.LDS1Formated, "d", new System.Globalization.CultureInfo("vi-VN"));
            }
            else
            {
                dtoItem.LDS1 = null;
            }

            if (!string.IsNullOrEmpty(dtoItem.LDS2Formated))
            {
                dtoItem.LDS2 = DateTime.ParseExact(dtoItem.LDS2Formated, "d", new System.Globalization.CultureInfo("vi-VN"));
            }
            else
            {
                dtoItem.LDS2 = null;
            }

            if (!string.IsNullOrEmpty(dtoItem.LDS3Formated))
            {
                dtoItem.LDS3 = DateTime.ParseExact(dtoItem.LDS3Formated, "d", new System.Globalization.CultureInfo("vi-VN"));
            }
            else
            {
                dtoItem.LDS3 = null;
            }

            if (!string.IsNullOrEmpty(dtoItem.LDS4Formated))
            {
                dtoItem.LDS4 = DateTime.ParseExact(dtoItem.LDS4Formated, "d", new System.Globalization.CultureInfo("vi-VN"));
            }
            else
            {
                dtoItem.LDS4 = null;
            }

            if (!string.IsNullOrEmpty(dtoItem.PSReceivedDateFormated))
            {
                dtoItem.PSReceivedDate = DateTime.ParseExact(dtoItem.PSReceivedDateFormated, "d", new System.Globalization.CultureInfo("vi-VN"));
            }
            else
            {
                dtoItem.PSReceivedDate = null;
            }

            if (!string.IsNullOrEmpty(dtoItem.PIReceivedDateFormated))
            {
                dtoItem.PIReceivedDate = DateTime.ParseExact(dtoItem.PIReceivedDateFormated, "d", new System.Globalization.CultureInfo("vi-VN"));
            }
            else
            {
                dtoItem.PIReceivedDate = null;
            }

            AutoMapper.Mapper.Map <DTO.FactoryOrderMng.FactoryOrder, FactoryOrder>(dtoItem, dbItem);
        }