Ejemplo n.º 1
0
        public ActionResult EditPurchaseRequestDetail(PurchaseRequestDetailModel purchaseRequestDetail)
        {
            if (Session["UserLogon"] != null)
            {
                purchaseRequestDetail.Account = (AccountModel)Session["UserLogon"];
            }
            PurchaseRequestDetailResponse _purchaserequestdetailresponse = new PurchaseRequestDetailResponse();
            var purchaserequestdetailrequest = new PurchaseRequestDetailRequest
            {
                Data = purchaseRequestDetail
            };
            var requestnamabarang = new ProductRequest
            {
                Data = new ProductModel
                {
                    Id = Convert.ToInt32(purchaseRequestDetail.ProductId)
                }
            };

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

            purchaserequestdetailrequest.Data.namabarang = purchaserequestdetailrequest.Data.namabarang != null ? purchaserequestdetailrequest.Data.namabarang : namabarang.Entity.Name;
            new PurchaseRequestDetailValidator(_unitOfWork).Validate(purchaserequestdetailrequest, out _purchaserequestdetailresponse);
            return(Json(new { data = _purchaserequestdetailresponse.Data }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public JsonResult CreateOrEditPurchaseRequest(PurchaseRequestModel _purchaserequest, List <PurchaseRequestDetailModel> purchaserequestDetailModels)
        {
            if (Session["UserLogon"] != null)
            {
                _purchaserequest.Account = (AccountModel)Session["UserLogon"];
            }
            _purchaserequest.Id = Convert.ToInt32(_purchaserequest.Id) > 0 ? _purchaserequest.Id : 0;
            var gudangid = _unitOfWork.GudangRepository.Query(a => a.ClinicId == _purchaserequest.Account.ClinicID).Select(x => x.id).FirstOrDefault();

            _purchaserequest.GudangId = gudangid > 0 ? gudangid : 0;
            var request = new PurchaseRequestRequest
            {
                Data = _purchaserequest
            };

            PurchaseRequestResponse _response = new PurchaseRequestResponse();

            new PurchaseRequestValidator(_unitOfWork).Validate(request, out _response);
            if (purchaserequestDetailModels != null)
            {
                foreach (var item in purchaserequestDetailModels)
                {
                    var purchaserequestdetailrequest = new PurchaseRequestDetailRequest
                    {
                        Data = item
                    };
                    purchaserequestdetailrequest.Data.PurchaseRequestId = Convert.ToInt32(_response.Entity.Id);
                    purchaserequestdetailrequest.Data.Account           = (AccountModel)Session["UserLogon"];
                    //
                    var requestnamabarang = new ProductRequest
                    {
                        Data = new ProductModel
                        {
                            Id = Convert.ToInt32(item.ProductId)
                        }
                    };

                    ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
                    purchaserequestdetailrequest.Data.namabarang = namabarang.Entity.Name;
                    PurchaseRequestDetailResponse _purchaserequestdetailresponse = new PurchaseRequestDetailResponse();
                    new PurchaseRequestDetailValidator(_unitOfWork).Validate(purchaserequestdetailrequest, out _purchaserequestdetailresponse);
                }
            }
            return(Json(new { data = _response.Data }, JsonRequestBehavior.AllowGet));
        }
        public void Validate(PurchaseRequestDetailRequest request, out PurchaseRequestDetailResponse response)
        {
            response = new PurchaseRequestDetailResponse();

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

                if (request.Data.namabarang == null || String.IsNullOrWhiteSpace(request.Data.namabarang))
                {
                    errorFields.Add("namabarang");
                }

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

                if (request.Data.Id == 0)
                {

                    isHavePrivilege = IsHaveAuthorization(ADD_M_PURCHASEREQUEST, request.Data.Account.Privileges.PrivilegeIDs);
                }
                else
                {
                    isHavePrivilege = IsHaveAuthorization(EDIT_M_PURCHASEREQUEST, request.Data.Account.Privileges.PrivilegeIDs);
                }

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

                if (response.Status)
                {
                    response = new PurchaseRequestDetailHandler(_unitOfWork).CreateOrEdit(request);
                }
            }
        }
        private void ValidateForDelete(PurchaseRequestDetailRequest request, out PurchaseRequestDetailResponse response)
        {
            response = new PurchaseRequestDetailResponse();

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

            if (response.Status)
            {
                //response = new DeliveryOrderHandler(_unitOfWork).RemoveData(request);
            }
        }