Ejemplo n.º 1
0
        public async Task <int> Update(SupplierUpdateRequest request)
        {
            var supplier = await _context.Suppliers.FindAsync(request.Supplier_ID);

            if (supplier == null)
            {
                throw new MyeshopException($"Nhà cung cấp không tồn tại");
            }
            supplier.Supplier_Name = request.Supplier_Name;
            supplier.Gmail         = request.Gmail;
            supplier.Address       = request.Address;
            supplier.Phone         = request.Phone;
            supplier.Status        = request.Status;

            //Save image
            //if (request.ThumbnailImage != null)
            //{
            //    var thumbnailImage = await _context.ProductImages.FirstOrDefaultAsync(i => i.IsDefault == true && i.Prod_ID == request.Prod_ID);
            //    if (thumbnailImage != null)
            //    {
            //        thumbnailImage.FileSize = request.ThumbnailImage.Length;
            //        thumbnailImage.ImagePath = await this.SaveFile(request.ThumbnailImage);
            //        _context.ProductImages.Update(thumbnailImage);
            //    }
            //}
            return(await _context.SaveChangesAsync());
        }
Ejemplo n.º 2
0
        public SupplierResponse Any(SupplierUpdateRequest request)
        {
            if (Validator != null)
            {
                Validator.ValidateAndThrow(request, ApplyTo.Put);
            }

            OnBeforeSupplierUpdateRequest(request);

            var output = Repository.Update(request);

            OnAfterSupplierUpdateRequest(request, output);
            return(output);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Update([FromBody] SupplierUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _supplierService.Update(request);

            //if (!result.IsSuccessed)
            //    return BadRequest(result);
            //return Ok(result);
            if (result == 0)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(SupplierUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var result = await _supplierApiClient.Update(request);

            if (result.IsSuccessed)
            {
                //TempData["result"] = "Cập nhật nhà sản xuất thành công";
                return(RedirectToAction("Index"));
            }

            //ModelState.AddModelError("", result.Message);
            return(View(request));
        }
        public SupplierResponse Update(SupplierUpdateRequest request)
        {
            using (var adapter = DataAccessAdapterFactory.NewDataAccessAdapter())
            {
                OnBeforeSupplierUpdateRequest(adapter, request);

                var entity = request.FromDto();
                entity.IsNew   = false;
                entity.IsDirty = true;

                if (adapter.SaveEntity(entity, true))
                {
                    OnAfterSupplierUpdateRequest(adapter, request);
                    return(new SupplierResponse(entity.ToDto()));
                }
            }

            throw new InvalidOperationException();
        }
Ejemplo n.º 6
0
        public async Task <ApiResult <int> > Update(SupplierUpdateRequest request)
        {
            var json        = JsonConvert.SerializeObject(request);
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
            var client      = _httpClientFactory.CreateClient();

            client.BaseAddress = new Uri("https://localhost:5001");
            var response = await client.PutAsync("/api/Suppliers/", httpContent);

            var Token = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                int t = (int)JsonConvert.DeserializeObject(Token, typeof(int));
                return(new ApiSuccessResult <int>(t));
            }


            return(new ApiErrorResult <int>(Token));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Edit(int id)
        {
            var result = await _supplierApiClient.GetById(id);

            if (result.IsSuccessed)
            {
                var s             = result.ResultObj;
                var updateRequest = new SupplierUpdateRequest()
                {
                    Supplier_Name = s.Supplier_Name,
                    Gmail         = s.Gmail,
                    Address       = s.Address,
                    Phone         = s.Phone,
                    Status        = s.Status,
                    Supplier_ID   = id
                };
                return(View(updateRequest));
            }
            return(RedirectToAction("Error", "Home"));
        }
Ejemplo n.º 8
0
 partial void OnAfterSupplierUpdateRequest(SupplierUpdateRequest request, SupplierResponse response);
Ejemplo n.º 9
0
 partial void OnBeforeSupplierUpdateRequest(SupplierUpdateRequest request);
 partial void OnAfterSupplierUpdateRequest(IDataAccessAdapter adapter, SupplierUpdateRequest request);