Пример #1
0
        public IActionResult Edit(EditCustomerDto customerDto)
        {
            List <CustomerTypeCustomer> entitiesToAdd = new List <CustomerTypeCustomer>();

            if (customerDto.CustomerTypeIds != null)
            {
                foreach (int customerTypeId in customerDto.CustomerTypeIds)
                {
                    entitiesToAdd.Add(new CustomerTypeCustomer {
                        CustomerTypeId = customerTypeId, CustomerId = customerDto.Id
                    });
                }
            }

            if (ModelState.IsValid)
            {
                _customerTypeCustomerRepository.DeleteAllTTypes(x => x.CustomerId == customerDto.Id);
                entitiesToAdd.ForEach(x => { _customerTypeCustomerRepository.Add(x); });

                Customer customer = _mapper.Map <Customer>(customerDto);

                _customerRepository.Update(customer);
                return(RedirectToAction("Index"));
            }

            customerDto.CustomerTypes = entitiesToAdd;
            TempData["CustomerTypes"] = _customerTypes;
            return(View(customerDto));
        }
Пример #2
0
        public IActionResult Edit(int id)
        {
            TempData["CustomerTypes"] = _customerTypes;
            Customer        customer    = _customerRepository.GetById(id);
            EditCustomerDto customerDto = _mapper.Map <EditCustomerDto>(customer);

            return(View(customerDto));
        }
Пример #3
0
        public async Task <IActionResult> EditCustomerInfo(long id, [FromBody] EditCustomerDto value)
        {
            var command = new EditCustomerInfoCommand(id,
                                                      value.FirstName,
                                                      value.LastName,
                                                      value.Age);


            var result = await messages.Dispatch(command);


            return(result.Match <IActionResult>(
                       (errors) => BadRequest(errors),
                       (valid) => NoContent()
                       ));
        }
        public IActionResult Edit(int id, EditCustomerDto editCustomerDto)
        {
            var customer = _repo.FindById(id);

            if (customer == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var cust = _mapper.Map <Customer>(editCustomerDto);
                _repo.Update(cust);
                return(Ok());
            }
            else
            {
                return(BadRequest("Customer data is not valid"));
            }
        }
Пример #5
0
        public ActionResult Edit(EditCustomerDto vm)
        {
            var id = Convert.ToInt32(Session["UserId"]);

            if (ModelState.IsValid)
            {
                var customer = new Customer();
                customer.Id        = vm.Id;
                customer.FirstName = vm.FirstName;
                customer.LastName  = vm.LastName;
                customer.Email     = vm.Email;
                customer.CellPhone = vm.CellPhone;
                customer.UserId    = id;

                _customerRepository.EditCustomer(customer);

                return(RedirectToAction("List"));
            }
            else
            {
                return(View(vm));
            }
        }
Пример #6
0
        public async Task <User> Edit(EditCustomerDto arguments, string imagePath)
        {
            var content = new MultipartFormDataContent
            {
                {
                    new StringContent(arguments.City), "city"
                },
                {
                    new StringContent(arguments.Country), "country"
                },
                {
                    new StringContent(arguments.Birthday.ToString("yyyy-MM-dd")), "birthday"
                },
                {
                    new StringContent(arguments.Car), "car"
                },
                {
                    new StringContent(arguments.Uuid.ToString()), "uuid"
                },
                {
                    new StringContent(arguments.Phone), "phone"
                },
                {
                    new StringContent(arguments.Sex), "sex"
                }
            };

            if (!string.IsNullOrWhiteSpace(arguments.Password))
            {
                content.Add(new StringContent(arguments.Password), "password");
            }

            if (!string.IsNullOrEmpty(imagePath) && !(Uri.TryCreate(imagePath, UriKind.Absolute, out var uriResult) &&
                                                      (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps)))
            {
                var byteArrayContent = new ByteArrayContent(File.ReadAllBytes(imagePath));
                content.Add(byteArrayContent, "\"photo\"", $"\"{imagePath.Substring(imagePath.LastIndexOf('/') + 1)}\"");
            }

            if (!await AuthService.UserIsAuthorized())
            {
                return(await FillInfo(content));
            }

            content.Add(new StringContent("PUT"), "_method");
            if (!await Update(content))
            {
                return(null);
            }

            var user = AuthService.User;

            user.City        = arguments.City;
            user.Country     = arguments.Country;
            user.Car         = arguments.Car;
            user.Sex         = arguments.Sex;
            user.Phone       = arguments.Phone;
            user.Birthday    = arguments.Birthday;
            user.PhotoSource = imagePath;

            _userRepository.Update(user);
            return(user);
        }