public async Task <IActionResult> Update(SupplierUpdateViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var supplier = new SupplierUpdateDTO()
                    {
                        Id      = model.Id,
                        Name    = model.Name,
                        Phone   = model.Phone,
                        Address = model.Address,
                        Email   = model.Email,
                    };

                    await _supplierService.Update(supplier).ConfigureAwait(true);

                    _toastNotification.AddInfoToastMessage("Updated to:- " + model.Name);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                _toastNotification.AddErrorToastMessage(ex.Message);
            }
            return(View());
        }
Beispiel #2
0
 public SupplierServiceTest()
 {
     _supplierService = new SupplierService(_supplierRepo.Object);
     _createDto       = new SupplierCreateDTO();
     _updateDto       = new SupplierUpdateDTO();
     _supplier        = new Supplier(full_name, address, email, phone);
 }
Beispiel #3
0
        public async Task <SupplierDTO> PatchAsync(SupplierUpdateDTO supplier)
        {
            this.Logger.LogTrace($"{nameof(this.PutAsync)} called");

            var result = await this.SupplierUpdateService.UpdateAsync(this.Mapper.Map <SupplierUpdateModel>(supplier));

            return(this.Mapper.Map <SupplierDTO>(result));
        }
        public async Task Update(int id, SupplierUpdateDTO model)
        {
            var entry = _context.Suppliers.Single(x => x.SupplierId == id);

            entry.SupplierId    = model.SupplierId;
            entry.Qualification = model.Qualification;

            await _context.SaveChangesAsync();
        }
        public IActionResult Updatesupplier(SupplierUpdateDTO supplier, Guid supplierID)
        {
            try
            {
                supplierService.UpdateSupplier(supplier, supplierID);

                return(NoContent());
            }
            catch
            {
                return(NotFound());
            }
        }
Beispiel #6
0
        public async Task <ActionResult> Update(int id, SupplierUpdateDTO model)
        {
            if (_SupplierService.Existencia(id) == true)
            {
                await _SupplierService.Update(id, model);

                return(NoContent());
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task Update(SupplierUpdateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var supplier = await _supplierRepo.GetById(dto.Id).ConfigureAwait(false) ?? throw new System.Exception("Supplier Not Found.");

            await ValidateSupplierNumber(dto.Phone, supplier);

            supplier.Update(dto.Name, dto.Address, dto.Email, dto.Phone);

            await _supplierRepo.UpdateAsync(supplier);

            tx.Complete();
        }
        public async Task <ActionResult> Update(SupplierUpdateViewModel model)
        {
            try
            {
                var supplier = new SupplierUpdateDTO()
                {
                    Id      = model.Id,
                    Name    = model.Name,
                    Phone   = model.Phone,
                    Address = model.Address,
                    Email   = model.Email,
                };

                await _supplierService.Update(supplier).ConfigureAwait(true);

                var Supplier = await _supplierRepo.GetByNumber(supplier.Phone) ?? throw new System.Exception("Supplier Not Found.");

                return(Ok(CreateReponseDto(Supplier)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
 public void UpdateSupplier(SupplierUpdateDTO supplier, Guid supplierID)
 {
     supplierRepository.UpdateSupplier(mapper.Map <Supplier>(supplier), supplierID);
 }
        public IActionResult Put(int id, [FromBody] SupplierUpdateDTO supplier)
        {
            if (supplier == null)
            {
                return(BadRequest(new ErrorViewModel
                {
                    ErrorCode = "400",
                    ErrorMessage = "Thông tin cung cấp không chính xác."
                }));
            }

            if (!ModelState.IsValid)
            {
                var errorViewModel = new ErrorViewModel
                {
                    ErrorCode    = "400",
                    ErrorMessage = ModelState.ToErrorMessages()
                };

                return(BadRequest(errorViewModel));
            }

            var supplierToUpdate = this._supplierRepository.GetById(id);

            if (supplierToUpdate == null)
            {
                return(NotFound(new ErrorViewModel
                {
                    ErrorCode = "404",
                    ErrorMessage = "Khách hàng cần cập nhật không tìm thấy"
                }));
            }

            bool isExisting = this._supplierRepository.CheckExistingSupplier(
                id, supplier.Name);

            if (isExisting)
            {
                return(BadRequest(new ErrorViewModel
                {
                    ErrorCode = "400",
                    ErrorMessage = "Tên nhà cung cấp này đã tồn tại."
                }));
            }

            //supplierToUpdate.Name = supplier.Name;
            supplierToUpdate.Address = supplier.Address;
            // supplierToUpdate.Contact = supplier.Contact;
            supplierToUpdate.UpdatedBy   = "admin";
            supplierToUpdate.UpdatedDate = DateTime.Now;

            bool isSuccess = this._supplierRepository.Update(supplierToUpdate);

            if (isSuccess == false)
            {
                return(StatusCode(500, new ErrorViewModel
                {
                    ErrorCode = "500",
                    ErrorMessage = "Có lỗi trong quá trình cập nhật dữ liệu."
                }));
            }

            return(Ok(supplierToUpdate));
        }
Beispiel #11
0
        /// <summary>
        /// 添加供用商
        /// </summary>
        /// <param name="searchDto"></param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO AddSupplierExt(SupplierUpdateDTO dto)
        {
            if (dto.AppIds == null || dto.AppIds.Count == 0)
            {
                return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO {
                    isSuccess = false, Message = "参数错误"
                });
            }
            ContextSession            contextSession = ContextFactory.CurrentThreadContext;
            var                       supplierMain   = SupplierMain.CreateSupplierMain();
            Dictionary <Guid, string> appNames       = new Dictionary <Guid, string>();

            foreach (var appId in dto.AppIds)
            {
                var supplier = Supplier.CreateSupplier();
                supplier.EsAppId = dto.EsAppId;
                supplier.AppId   = appId;
                var appName = Jinher.AMP.BTP.TPS.APPSV.GetAppName(appId);
                if (appName == "")
                {
                    appName = MallApply.ObjectSet().Where(_ => _.EsAppId == supplier.EsAppId && _.AppId == supplier.AppId).Select(_ => _.AppName).FirstOrDefault();
                }
                appNames.Add(appId, appName);
                supplier.AppName        = appName;
                supplier.SubId          = dto.SubId;
                supplier.SupplierName   = dto.SupplierName;
                supplier.SupplierCode   = dto.SupplierCode;
                supplier.SupplierType   = dto.SupplierType;
                supplier.ShipperType    = dto.ShipperType;
                supplier.IsDel          = false;
                supplier.SupplierMainId = supplierMain.Id;
                contextSession.SaveObject(supplier);

                // 同步MallApply表
                var mallApply = MallApply.ObjectSet().Where(_ => _.EsAppId == supplier.EsAppId && _.AppId == supplier.AppId /*&& _.State.Value == (int)Jinher.AMP.BTP.Deploy.Enum.MallApplyEnum.TG*/).FirstOrDefault();
                if (mallApply != null)
                {
                    if (mallApply.AppName != supplier.AppName || mallApply.Type != supplier.SupplierType)
                    {
                        mallApply.Type        = supplier.SupplierType;
                        mallApply.AppName     = supplier.AppName;
                        mallApply.EntityState = System.Data.EntityState.Modified;
                        contextSession.SaveObject(mallApply);
                    }
                }
            }
            supplierMain.EsAppId      = dto.EsAppId;
            supplierMain.AppIds       = string.Join(",", dto.AppIds);
            supplierMain.AppNames     = string.Join(",", appNames.Values);
            supplierMain.SubId        = dto.SubId;
            supplierMain.SupplierName = dto.SupplierName;
            supplierMain.SupplierCode = dto.SupplierCode;
            supplierMain.SupplierType = dto.SupplierType;
            supplierMain.ShipperType  = dto.ShipperType;
            supplierMain.IsDel        = false;
            contextSession.SaveObject(supplierMain);

            try
            {
                contextSession.SaveChanges();
            }
            catch (Exception ex)
            {
                LogHelper.Error("Supplier.AddSupplierExt 异常", ex);
                return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO {
                    isSuccess = false, Message = ex.Message
                });
            }
            return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO {
                isSuccess = true
            });
        }