예제 #1
0
        public void Create(PurchaseRequestPusatResponse _response)
        {
            var searchPredicate = PredicateBuilder.New <PurchaseOrderPusat>(true);

            var purchaseorderpusatrequest = new PurchaseOrderPusatRequest
            {
                Data = Mapper.Map <PurchaseRequestPusatModel, PurchaseOrderPusatModel>(_response.Entity)
            };

            purchaseorderpusatrequest.Data.approve           = 1;
            purchaseorderpusatrequest.Data.podate            = DateTime.Now;
            purchaseorderpusatrequest.Data.Validasi          = null;
            purchaseorderpusatrequest.Data.approve_by        = OneLoginSession.Account.UserCode;
            purchaseorderpusatrequest.Data.PurchaseRequestId = Convert.ToInt32(_response.Entity.Id);
            purchaseorderpusatrequest.Data.Id = 0;

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

            purchaseorderpusatrequest.Data.ponumber = "PO" + _response.Entity.Account.Organization + DateTime.Now.Year + DateTime.Now.Month + ponumber;
            purchaseorderpusatrequest.Data.Account  = _response.Entity.Account;

            PurchaseOrderPusatResponse purchaseorderresponse = new PurchaseOrderPusatResponse();

            new PurchaseOrderPusatValidator(_unitOfWork).Validate(purchaseorderpusatrequest, out purchaseorderresponse);

            if (_response.Entity.purchaserequestPusatdetailModels != null)
            {
                int i = 0;
                foreach (var item in _response.Entity.purchaserequestPusatdetailModels)
                {
                    var purchaseorderdetailrequest = new PurchaseOrderPusatDetailRequest
                    {
                        Data = Mapper.Map <PurchaseRequestPusatDetailModel, PurchaseOrderPusatDetailModel>(item)
                    };
                    purchaseorderdetailrequest.Data.PurchaseOrderPusatId = Convert.ToInt32(purchaseorderresponse.Entity.Id);
                    purchaseorderdetailrequest.Data.Account = _response.Entity.Account;
                    purchaseorderdetailrequest.Data.Id      = 0;
                    //
                    var requestnamabarang = new ProductRequest
                    {
                        Data = new ProductModel
                        {
                            Id = Convert.ToInt32(item.ProductId)
                        }
                    };

                    ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
                    purchaseorderdetailrequest.Data.namabarang = namabarang.Entity.Name;
                    PurchaseOrderPusatDetailResponse _purchaseorderdetailresponse = new PurchaseOrderPusatDetailResponse();
                    new PurchaseOrderPusatDetailValidator(_unitOfWork).Validate(purchaseorderdetailrequest, out _purchaseorderdetailresponse);
                    i++;
                }
            }
        }
예제 #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
        /// <summary>
        /// Validate request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        public void Validate(ProductRequest request, out ProductResponse response)
        {
            response = new ProductResponse();

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

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

                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 ProductHandler(_unitOfWork).CreateOrEdit(request);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Delete validation
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private void ValidateForDelete(ProductRequest request, out ProductResponse response)
        {
            response = new ProductResponse();

            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 ProductHandler(_unitOfWork).RemoveData(request);
            }
        }