コード例 #1
0
        public DTO.CostInvoiceMng.CostInvoice DB2DTO_CostInvoice(CostInvoiceMng_CostInvoice_View dbItem)
        {
            DTO.CostInvoiceMng.CostInvoice dtoItem = AutoMapper.Mapper.Map <CostInvoiceMng_CostInvoice_View, DTO.CostInvoiceMng.CostInvoice>(dbItem);

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

            if (dbItem.InvoiceDate.HasValue)
            {
                dtoItem.InvoiceDateFormated = dbItem.InvoiceDate.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);
        }
コード例 #2
0
        public IHttpActionResult Update(int id, DTO.CostInvoiceMng.CostInvoice 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.CostInvoiceMng.CostInvoice>(dtoItem, out notification))
            {
                return(Ok(new Library.DTO.ReturnData <DTO.CostInvoiceMng.CostInvoice>()
                {
                    Data = dtoItem, Message = notification
                }));
            }

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

            return(Ok(new Library.DTO.ReturnData <DTO.CostInvoiceMng.CostInvoice>()
            {
                Data = dtoItem, Message = notification
            }));
        }
コード例 #3
0
        public void DTO2DB_CostInvoice(DTO.CostInvoiceMng.CostInvoice dtoItem, ref CostInvoice dbItem)
        {
            List <CostInvoiceDetail>       itemNeedDelete_Details = new List <CostInvoiceDetail>();
            List <CostInvoiceDetailExtend> itemNeedDelete_DetailExtends;

            if (dtoItem.CostInvoiceDetails != null)
            {
                //CHECK
                foreach (CostInvoiceDetail dbDetail in dbItem.CostInvoiceDetail)
                {
                    //DB NOT EXIST IN DTO
                    if (!dtoItem.CostInvoiceDetails.Select(s => s.CostInvoiceDetailID).Contains(dbDetail.CostInvoiceDetailID))
                    {
                        itemNeedDelete_Details.Add(dbDetail);
                    }
                    else //DB IS EXIST IN DB
                    {
                        itemNeedDelete_DetailExtends = new List <CostInvoiceDetailExtend>();
                        foreach (CostInvoiceDetailExtend dbDetailExt in dbDetail.CostInvoiceDetailExtend)
                        {
                            if (!dtoItem.CostInvoiceDetails.Where(o => o.CostInvoiceDetailID == dbDetail.CostInvoiceDetailID).FirstOrDefault().CostInvoiceDetailExtends.Select(x => x.CostInvoiceDetailExtendID).Contains(dbDetailExt.CostInvoiceDetailExtendID))
                            {
                                itemNeedDelete_DetailExtends.Add(dbDetailExt);
                            }
                        }
                        foreach (CostInvoiceDetailExtend dbDetailExt in itemNeedDelete_DetailExtends)
                        {
                            dbDetail.CostInvoiceDetailExtend.Remove(dbDetailExt);
                        }
                    }
                }

                foreach (CostInvoiceDetail dbDetail in itemNeedDelete_Details)
                {
                    List <CostInvoiceDetailExtend> item_deleteds = new List <CostInvoiceDetailExtend>();
                    foreach (CostInvoiceDetailExtend dbDetailExtend in dbDetail.CostInvoiceDetailExtend)
                    {
                        item_deleteds.Add(dbDetailExtend);
                    }
                    foreach (CostInvoiceDetailExtend item in item_deleteds)
                    {
                        dbItem.CostInvoiceDetail.Where(o => o.CostInvoiceDetailID == dbDetail.CostInvoiceDetailID).FirstOrDefault().CostInvoiceDetailExtend.Remove(item);
                    }
                    dbItem.CostInvoiceDetail.Remove(dbDetail);
                }

                //MAP
                CostInvoiceDetail       _dbDetail;
                CostInvoiceDetailExtend _dbDetailExtend;
                foreach (DTO.CostInvoiceMng.CostInvoiceDetail dtoDetail in dtoItem.CostInvoiceDetails)
                {
                    dtoDetail.CostType = dtoItem.CostType;
                    dtoDetail.ClientID = dtoItem.ClientID;

                    if (dtoDetail.CostInvoiceDetailID < 0)
                    {
                        _dbDetail = new CostInvoiceDetail();

                        if (dtoDetail.CostInvoiceDetailExtends != null)
                        {
                            foreach (DTO.CostInvoiceMng.CostInvoiceDetailExtend dtoDetailExtend in dtoDetail.CostInvoiceDetailExtends)
                            {
                                _dbDetailExtend = new CostInvoiceDetailExtend();
                                _dbDetail.CostInvoiceDetailExtend.Add(_dbDetailExtend);
                                AutoMapper.Mapper.Map <DTO.CostInvoiceMng.CostInvoiceDetailExtend, CostInvoiceDetailExtend>(dtoDetailExtend, _dbDetailExtend);
                            }
                        }

                        dbItem.CostInvoiceDetail.Add(_dbDetail);
                    }
                    else
                    {
                        _dbDetail = dbItem.CostInvoiceDetail.FirstOrDefault(o => o.CostInvoiceDetailID == dtoDetail.CostInvoiceDetailID);
                        if (_dbDetail != null && dtoDetail.CostInvoiceDetailExtends != null)
                        {
                            foreach (DTO.CostInvoiceMng.CostInvoiceDetailExtend dtoDetailExtend in dtoDetail.CostInvoiceDetailExtends)
                            {
                                if (dtoDetailExtend.CostInvoiceDetailExtendID < 0)
                                {
                                    _dbDetailExtend = new CostInvoiceDetailExtend();
                                    _dbDetail.CostInvoiceDetailExtend.Add(_dbDetailExtend);
                                }
                                else
                                {
                                    _dbDetailExtend = _dbDetail.CostInvoiceDetailExtend.FirstOrDefault(o => o.CostInvoiceDetailExtendID == dtoDetailExtend.CostInvoiceDetailExtendID);
                                }
                                if (_dbDetailExtend != null)
                                {
                                    AutoMapper.Mapper.Map <DTO.CostInvoiceMng.CostInvoiceDetailExtend, CostInvoiceDetailExtend>(dtoDetailExtend, _dbDetailExtend);
                                }
                            }
                        }
                    }

                    if (_dbDetail != null)
                    {
                        AutoMapper.Mapper.Map <DTO.CostInvoiceMng.CostInvoiceDetail, CostInvoiceDetail>(dtoDetail, _dbDetail);
                    }
                }
            }

            AutoMapper.Mapper.Map <DTO.CostInvoiceMng.CostInvoice, CostInvoice>(dtoItem, dbItem);

            if (dtoItem.CostInvoiceID > 0)
            {
                dbItem.UpdatedBy   = dtoItem.UpdatedBy;
                dbItem.UpdatedDate = DateTime.Now;
            }
            else
            {
                dbItem.CreatedBy   = dtoItem.UpdatedBy;
                dbItem.CreatedDate = DateTime.Now;
            }
            dbItem.InvoiceDate = dtoItem.InvoiceDateFormated.ConvertStringToDateTime();
        }