Пример #1
0
        public ActionResult EditDeliveryOrderDetail(DeliveryOrderDetailModel deliveryorderdetail)
        {
            if (Session["UserLogon"] != null)
            {
                deliveryorderdetail.Account = (AccountModel)Session["UserLogon"];
            }
            DeliveryOrderDetailResponse _purchaseorderdetailresponse = new DeliveryOrderDetailResponse();
            var purchaserequestdetailrequest = new DeliveryOrderDetailRequest
            {
                Data = deliveryorderdetail
            };
            var requestnamabarang = new ProductRequest
            {
                Data = new ProductModel
                {
                    Id = Convert.ToInt32(deliveryorderdetail.ProductId)
                }
            };

            ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);

            purchaserequestdetailrequest.Data.namabarang = purchaserequestdetailrequest.Data.namabarang != null ? purchaserequestdetailrequest.Data.namabarang : namabarang.Entity.Name;
            new DeliveryOrderDetailValidator(_unitOfWork).Validate(purchaserequestdetailrequest, out _purchaseorderdetailresponse);
            return(Json(new { data = _purchaseorderdetailresponse.Data }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public void Create(PurchaseOrderResponse _response)
        {
            var searchPredicate = PredicateBuilder.New <Data.DataRepository.DeliveryOrder>(true);

            _response.Entity.approve   = null;
            _response.Entity.approveby = null;

            var request = new DeliveryOrderRequest
            {
                Data = Mapper.Map <PurchaseOrderModel, DeliveryOrderModel>(_response.Entity)
            };

            request.Data.dodate = DateTime.Now;
            request.Data.poid   = Convert.ToInt32(_response.Entity.Id);
            request.Data.Id     = 0;

            var      lastponumber = _unitOfWork.DeliveryOrderRepository.Get(searchPredicate, orderBy: a => a.OrderByDescending(x => x.CreatedDate)).Select(a => a.donumber).FirstOrDefault();
            DateTime?getmonth     = _unitOfWork.DeliveryOrderRepository.Get(searchPredicate, orderBy: a => a.OrderByDescending(x => x.CreatedDate)).Select(a => a.dodate).FirstOrDefault();
            DateTime?month        = getmonth != null ? getmonth : DateTime.Now;
            string   ponumber     = lastponumber != null?GeneralHandler.stringincrement(lastponumber, Convert.ToDateTime(month)) : "00001";

            request.Data.donumber = "DO" + _response.Entity.Account.Organization + DateTime.Now.Year + DateTime.Now.Month + ponumber;
            request.Data.Account  = _response.Entity.Account;

            DeliveryOrderResponse deliveryorderresponse = new DeliveryOrderResponse();

            new DeliveryOrderValidator(_unitOfWork).Validate(request, out deliveryorderresponse);

            if (_response.Entity.PurchaseOrderDetails != null)
            {
                int i = 0;
                foreach (var item in _response.Entity.PurchaseOrderDetails)
                {
                    var deliveryorderdetailrequest = new DeliveryOrderDetailRequest
                    {
                        Data = Mapper.Map <PurchaseOrderDetailModel, DeliveryOrderDetailModel>(item)
                    };
                    deliveryorderdetailrequest.Data.DeliveryOderId = Convert.ToInt32(deliveryorderresponse.Entity.Id);
                    deliveryorderdetailrequest.Data.Account        = _response.Entity.Account;
                    deliveryorderdetailrequest.Data.Id             = 0;
                    //
                    var requestnamabarang = new ProductRequest
                    {
                        Data = new ProductModel
                        {
                            Id = Convert.ToInt32(item.ProductId)
                        }
                    };

                    ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
                    deliveryorderdetailrequest.Data.namabarang = namabarang.Entity.Name;
                    DeliveryOrderDetailResponse _deliveryorderdetailresponse = new DeliveryOrderDetailResponse();
                    new DeliveryOrderDetailValidator(_unitOfWork).Validate(deliveryorderdetailrequest, out _deliveryorderdetailresponse);
                    i++;
                }
            }
        }
Пример #3
0
        public JsonResult CreateOrEditDeliveryOrder(DeliveryOrderModel _deliveryorder, List <DeliveryOrderDetailModel> deliveryOrderDetailModels)
        {
            if (Session["UserLogon"] != null)
            {
                _deliveryorder.Account = (AccountModel)Session["UserLogon"];
            }
            _deliveryorder.Id = Convert.ToInt32(_deliveryorder.Id) > 0 ? _deliveryorder.Id : 0;
            var request = new DeliveryOrderRequest
            {
                Data = _deliveryorder
            };

            DeliveryOrderResponse _response = new DeliveryOrderResponse();

            new DeliveryOrderValidator(_unitOfWork).Validate(request, out _response);
            DeliveryOrderDetailResponse _deliveryorderdetailresponse = new DeliveryOrderDetailResponse();

            if (deliveryOrderDetailModels != null)
            {
                foreach (var item in deliveryOrderDetailModels)
                {
                    var deliveryorderdetailrequest = new DeliveryOrderDetailRequest
                    {
                        Data = item
                    };
                    deliveryorderdetailrequest.Data.Account = (AccountModel)Session["UserLogon"];
                    //
                    var requestnamabarang = new ProductRequest
                    {
                        Data = new ProductModel
                        {
                            Id = item.ProductId
                        }
                    };

                    ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
                    deliveryorderdetailrequest.Data.namabarang = namabarang.Entity.Name;
                    new DeliveryOrderDetailValidator(_unitOfWork).Validate(deliveryorderdetailrequest, out _deliveryorderdetailresponse);
                }
            }

            return(Json(new { data = _deliveryorderdetailresponse.Data }, JsonRequestBehavior.AllowGet));
        }
        private void ValidateForDelete(DeliveryOrderDetailRequest request, out DeliveryOrderDetailResponse response)
        {
            response = new DeliveryOrderDetailResponse();

            if (request.Action == ClinicEnums.Action.DELETE.ToString())
            {
                bool isHavePrivilege = IsHaveAuthorization(DELETE_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }
            }

            if (response.Status)
            {
                //response = new DeliveryOrderHandler(_unitOfWork).RemoveData(request);
            }
        }
        public void Validate(DeliveryOrderDetailRequest request, out DeliveryOrderDetailResponse response)
        {
            response = new DeliveryOrderDetailResponse();

            if (request.Action != null && request.Action.Equals(ClinicEnums.Action.DELETE.ToString()))
            {
                ValidateForDelete(request, out response);
            }
            else
            {
                bool isHavePrivilege = true;

                if (errorFields.Any())
                {
                    response.Status  = false;
                    response.Message = string.Format(Messages.ValidationErrorFields, String.Join(",", errorFields));
                }

                if (request.Data.Id == 0)
                {
                    isHavePrivilege = IsHaveAuthorization(ADD_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                }
                else
                {
                    isHavePrivilege = IsHaveAuthorization(EDIT_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                }

                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }

                if (response.Status)
                {
                    response = new DeliveryOrderDetailHandler(_unitOfWork).CreateOrEdit(request);
                }
            }
        }