public async Task <IActionResult> Update(CustomerUpdateViewModel model) { try { var customer = new CustomerUpdateDTO { CusId = model.CusId, FullName = model.FullName, Address = model.Address, PhoneNumber = model.PhoneNumber, Gender = model.Gender, Email = model.Email }; await _customerService.Update(customer).ConfigureAwait(true); _toastNotification.AddSuccessToastMessage("Updated to :- " + customer.FullName); } catch (Exception ex) { _toastNotification.AddErrorToastMessage(ex.Message); } return(RedirectToAction("Index")); }
public IActionResult UpdateCustomer(int id, [FromBody] CustomerUpdateDTO customerDTO) { try { var existingCustomer = _customerManager.GetById(id); if (existingCustomer == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest("Customer Not Found")); } var customer = _mapper.Map(customerDTO, existingCustomer); bool isUpdate = _customerManager.Update(customer); if (isUpdate) { return(Ok(customer)); } else { return(BadRequest("Update Failed")); } } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <ActionResult> Update(CustomerUpdateViewModel model) { try { var CustomerDto = new CustomerUpdateDTO { CusId = model.CusId, FullName = model.FullName, Address = model.Address, PhoneNumber = model.PhoneNumber, Gender = model.Gender, Email = model.Email }; await _customerService.Update(CustomerDto).ConfigureAwait(true); var Customer = await _customerRepo.GetByNumber(CustomerDto.PhoneNumber) ?? throw new CustomerNotFoundException(); return(Ok(CreateReponseDto(Customer))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult PutCustomer(int id,[FromBody] CustomerUpdateDTO CustomerDTO) { try { var existingCustomer = _customerManager.GetById(id); if (existingCustomer == null) { return NotFound(); } if (!ModelState.IsValid) { return BadRequest(ModelState); } var customer = _mapper.Map(CustomerDTO, existingCustomer); bool IsUpdated = _customerManager.Update(customer); if (IsUpdated) { return Ok(); } else { return BadRequest("Update Failed!"); } } catch(Exception ex) { return BadRequest("System Error Occured!"); } }
public IActionResult PutCustomer(int?id, [FromBody] CustomerUpdateDTO CustomerDto) { try { var existingCustomer = _customerManager.GetById(id); if (existingCustomer == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //map update dto data to existing customer data var customer = _mapper.Map(CustomerDto, existingCustomer); var isUpdated = _customerManager.Update(customer); if (isUpdated) { return(Ok()); } else { return(BadRequest("Update Failed!")); } } catch (Exception ex) { return(BadRequest("Server error occured. Please contact with the vendor")); } }
public bool UpdateCustomer(CustomerUpdateDTO objCustomer) { bool res = false; SqlCommand SqlCmd = new SqlCommand("spUpdateCustomer"); SqlCmd.CommandType = CommandType.StoredProcedure; SqlCmd.Parameters.AddWithValue("@Id", objCustomer.Id); SqlCmd.Parameters.AddWithValue("@Name", objCustomer.Name); SqlCmd.Parameters.AddWithValue("@ContactNo", objCustomer.ContactNo); SqlCmd.Parameters.AddWithValue("@Email", objCustomer.Email); SqlCmd.Parameters.AddWithValue("@Address", objCustomer.Address); SqlCmd.Parameters.AddWithValue("@ConcernPerson", objCustomer.ConcernPerson); SqlCmd.Parameters.AddWithValue("@ContactPerson", objCustomer.ContactPerson); SqlCmd.Parameters.AddWithValue("@State", objCustomer.State); SqlCmd.Parameters.AddWithValue("@City", objCustomer.City); SqlCmd.Parameters.AddWithValue("@CompanyId", objCustomer.CompanyId); SqlCmd.Parameters.AddWithValue("@IGST", objCustomer.IGST); SqlCmd.Parameters.AddWithValue("@CGST", objCustomer.CGST); SqlCmd.Parameters.AddWithValue("@SGST", objCustomer.SGST); SqlCmd.Parameters.AddWithValue("@PANNumber", objCustomer.PANNumber); SqlCmd.Parameters.AddWithValue("@GSTNumber", objCustomer.GSTNo); SqlCmd.Parameters.AddWithValue("@CINNumber", objCustomer.CINNumber); SqlCmd.Parameters.AddWithValue("@ModifiedBy", objCustomer.ModifiedBy); SqlCmd.Parameters.AddWithValue("@Active", objCustomer.Active); int result = _unitOfWork.DbLayer.ExecuteNonQuery(SqlCmd); if (result != Int32.MaxValue) { res = true; } return(res); }
public async Task <IActionResult> Put([FromBody] CustomerUpdateDTO customerUpdateDTO) { CustomerUpdateModel StaffUpdate = new DTOMapper <CustomerUpdateDTO, CustomerUpdateModel>().Serialize(customerUpdateDTO); int UpdateId = await _iCustomerService.UpdateCustomers(StaffUpdate); return(Ok(UpdateId)); }
public CustomerServiceTest() { _customerService = new CustomerService(_customerRepo.Object, _context.Object); _createDto = new CustomerCreateDTO(); _updateDto = new CustomerUpdateDTO(); _customer = new Customer(full_name); }
public async Task <IActionResult> UpdateCustomer(string accountId, [FromBody] CustomerUpdateDTO customerUpdateDTO) { try { if (string.IsNullOrWhiteSpace(accountId)) { ModelState.AddModelError("AccountId", "AccountId can't be null or empty."); return(BadRequest(ModelState)); } if (customerUpdateDTO == null) { ModelState.AddModelError("Customer", "Customer object can't be null"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var customer = _choiceRepoistory.GetById <Customer>(c => c.AccountId == accountId); if (customer == null) { ModelState.AddModelError("Customer", $"No customer found with AccountId {accountId}"); return(NotFound(ModelState)); } customer.Address1 = customerUpdateDTO.Address1; customer.Address2 = customerUpdateDTO.Address2; customer.CompanyName = customerUpdateDTO.CompanyName; customer.Country = customerUpdateDTO.Country; customer.IndustryCode = customerUpdateDTO.IndustryCode; customer.PhoneNumber = customerUpdateDTO.PhoneNumber; customer.PostNumber = customerUpdateDTO.PostNumber; customer.StateAgreement = customerUpdateDTO.StateAgreement; customer.Town = customerUpdateDTO.Town; customer.LastModified = DateTime.UtcNow; customer.LastModifiedBy = "CRM"; _choiceRepoistory.Attach(customer); if (bool.Parse(_configuration["SharePointIntegrationEnabled"].ToString())) { var status = await _sharePointService.UpdateCustomerAsync(customer); if (!status) { return(StatusCode(500, "An error occurred while creating sharepoint customer. Please try again or contact adminstrator")); } } _choiceRepoistory.Complete(); return(NoContent()); } catch (Exception ex) { return(StatusCode(500, "An error occurred while updating Customer. Please try again or contact adminstrator")); } }
public async Task <CustomerDTO> Create([FromRoute] int?id, [FromBody] CustomerUpdateDTO customerUpdate) { if (id.HasValue && id != customerUpdate.Id) { throw new InvalidDataException(nameof(id)); } return(Mapper.Map <CustomerDTO>( await CustomerUpdateService.UpdateAsync(Mapper.Map <CustomerUpdateModel>(customerUpdate)))); }
public async Task <IActionResult> Edit(int id, CustomerUpdateDTO customerUpdate) { if (id != customerUpdate.Id) { return(NotFound()); } var customer = Mapper.Map <CustomerDTO>(await CustomerUpdateService.UpdateAsync(Mapper.Map <CustomerUpdateModel>(customerUpdate))); return(Redirect($"/customers/{customer.Id}")); }
public async Task <bool> UpdateCustomer(CustomerUpdateDTO customerUpdateDTO, Guid id) { try { var _uri = new Uri(_baseUri, ApiStrings.CustomerUrl + $"/{id}"); await _genericRepository.PutAsync(_uri.AbsoluteUri, customerUpdateDTO); return(true); } catch { return(false); } }
public IActionResult ClientUpdateCustomer(int id, [FromBody] CustomerUpdateDTO dto) { var customer = _context.Customers.FirstOrDefault(c => c.Id == id); if (customer == null) { return(Ok(ResponseDTO.BadRequest("CustomerId is not found."))); } customer.PhoneNumber = dto.phoneNumber; customer.Email = dto.email; customer.Gender = dto.gender; customer.Name = dto.name; _context.SaveChanges(); return(Ok(ResponseDTO.Ok(customer))); }
public HttpResponseMessage UpdateCustomer(CustomerUpdateDTO objCustomer) { HttpResponseMessage message; try { // CustomerDataAccessLayer dal = new CustomerDataAccessLayer(); var dynObj = new { result = _Customer.UpdateCustomer(objCustomer) }; message = Request.CreateResponse(HttpStatusCode.OK, dynObj); } catch (Exception ex) { message = Request.CreateResponse(HttpStatusCode.BadRequest, new { msgText = " Somthing wrong,try Again!" }); ErrorLog.CreateErrorMessage(ex, "Customer", "UpdateCustomer"); } return(message); }
public async Task Update(CustomerUpdateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); var customer = await _customerRepo.GetById(dto.CusId).ConfigureAwait(false); await ValidateCustomerNumber(dto.PhoneNumber, customer).ConfigureAwait(false); customer.Update(dto.FullName); customer.Email = dto.Email; customer.PhoneNumber = dto.PhoneNumber; customer.Gender = dto.Gender; customer.Address = dto.Address; await _customerRepo.UpdateAsync(customer); tx.Complete(); }
public async Task <IActionResult> UpdateCustomer(Guid id, [FromBody] CustomerUpdateDTO customer) { var customerEntity = await _customerRepository.GetCustomerAsync(id); if (customerEntity == null) { return(NotFound()); } Mapper.Map(customer, customerEntity); if (!await _customerRepository.SaveAsync()) { throw new Exception($"Updating customer failed on save"); } return(Ok()); }
public IActionResult UpdateCustomer(Guid id, [FromBody] CustomerUpdateDTO updateDTO) { var existingCustomer = _customerRepository.GetSingle(id); if (existingCustomer == null) { return(NotFound()); } Mapper.Map(updateDTO, existingCustomer); _customerRepository.Update(existingCustomer); bool result = _customerRepository.Save(); if (!result) { return(new StatusCodeResult(500)); } return(Ok(Mapper.Map <CustomerDTO>(existingCustomer))); }
public IActionResult Put(int id, [FromBody] CustomerUpdateDTO customer) { if (customer == 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 customerToUpdate = this._customerRepository.GetById(id); if (customerToUpdate == 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._customerRepository.CheckExistingCustomer( id, customer.FirstName, customer.LastName); if (isExisting) { return(BadRequest(new ErrorViewModel { ErrorCode = "400", ErrorMessage = "Họ và tên khách hàng này đã tồn tại." })); } customerToUpdate.FirstName = customer.FirstName; customerToUpdate.LastName = customer.LastName; customerToUpdate.Address = customer.Address; customerToUpdate.Contact = customer.Contact; customerToUpdate.UpdatedBy = "admin"; customerToUpdate.UpdatedDate = DateTime.Now; bool isSuccess = this._customerRepository.Update(customerToUpdate); 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(customerToUpdate)); }