コード例 #1
0
        public async Task <ActionResult> AddSupplier(RequestWareSupplierRequest request)
        {
            var requestWare = _da.GetRequestWareById(request.RequestWareId);

            if (requestWare == null)
            {
                return(Json(new JsonMessage()
                {
                    Erros = true, Message = "Request not exits"
                }, JsonRequestBehavior.AllowGet));
            }

            //remove nha cung cap
            if (request.SupplierId == 0)
            {
                var requestSuppliers = _da.GetAllRequestWareByRequestWareId(requestWare.GID);
                foreach (var dnRequestWareSupplier in requestSuppliers)
                {
                    dnRequestWareSupplier.IsDelete = true;
                }

                _da.Save();
                return(Json(new JsonMessage(false, "Đã bỏ chọn NCC")));
            }

            var requestWareSupplier = _da.GetRequestWareBySupplier(request.RequestWareId, request.SupplierId);

            if (requestWareSupplier != null)
            {
                return(Json(new JsonMessage()
                {
                    Erros = true, Message = requestWareSupplier.DN_Supplier.Name + " đã được chọn"
                }, JsonRequestBehavior.AllowGet));
            }

            var item = new DN_RequestWareSupplier()
            {
                RequestWareId = request.RequestWareId,
                SupplierId    = request.SupplierId,
                Quantity      = requestWare.Quantity ?? 0,
                IsDelete      = false
            };

            _da.AddRequestWareSupplier(item);


            _da.Save();
            return(Json(new JsonMessage(false, "Đã thêm NCC"), JsonRequestBehavior.AllowGet));
        }