public Customer CustomerForUpdate(UpdatedCustomerDto customer) { Customer old = new Customer() { Id = customer.id, FullName = customer.FullName, Tin = customer.tin, Email = customer.email, Type = customer.type, CreditLimit = customer.creditLimit, PaymentPeriod = customer.paymentPeriod }; foreach (var item in customer.telephones) { if ((item.id == null || item.id == 0) && !_customerQuery.IsPhoneUnique(item.number.Trim())) { throw new DuplicatePhonenumberException(item.number); } PhoneNumber phone = new PhoneNumber() { Id = (uint)item.id, Number = item.number, Type = item.type }; old.PhoneNumber.Add(phone); } foreach (var item in customer.socialMedias) { SocialMedia social = new SocialMedia() { Id = (uint)item.Id, Site = item.site, Address = item.address }; old.SocialMedia.Add(social); } foreach (var item in customer.addresses) { Address address = new Address() { Id = (uint)item.Id, Country = item.Country, City = item.City, SubCity = item.SubCity, Location = item.Location }; old.Address.Add(address); } return(old); }
public ActionResult UpdateCustomerRecord(uint id, [FromBody] UpdatedCustomerDto updatedData) { try { if (updatedData == null) { return(StatusCode(400)); } if (!ModelState.IsValid) { return(new InvalidInputResponse(ModelState)); } var customer = _query.GetCustomerById(id); if (customer == null) { return(StatusCode(404, $"Customer with id: {id} Not Found ")); } var customerFactory = _factory.CustomerForUpdate(updatedData); var result = _command.UpdateCustomerData(customerFactory); if (result == true) { return(StatusCode(204)); } else { return(StatusCode(500, "Something Wrong Happened Try Again")); } } catch (DuplicatePhonenumberException e) { ModelState.AddModelError("Duplicate Phone", e.Message); return(new InvalidInputResponse(ModelState)); } catch (Exception e) { _logger.LogError(500, e.StackTrace, e.Message); return(StatusCode(500, "Unknown error occured")); } }
public async Task Delete(Guid Id, UpdatedCustomerDto updatedCustomer) { await Mediator.Send(new UpdateCustomerCommand { UpdatedCustomer = updatedCustomer }); }