public async Task <IActionResult> UpdateBooking(string reservationId, [FromBody] CustomerForUpdateDto customerForUpdateDto)
        {
            var customerForUpdateBooking = await _repoForRoom.changeBooking(reservationId);

            //  if (!ModelState.IsValid)
            //     return BadRequest(ModelState);
            customerForUpdateBooking.FirstName         = customerForUpdateDto.FirstName.ToUpper();
            customerForUpdateBooking.LastName          = customerForUpdateDto.LastName.ToUpper();
            customerForUpdateBooking.DateOfArriving    = customerForUpdateDto.DateOfArriving.Date;
            customerForUpdateBooking.DateOfLeaving     = customerForUpdateDto.DateOfLeaving.Date;
            customerForUpdateBooking.DateOfReservation = DateTime.Now;
            customerForUpdateBooking.Price             = customerForUpdateDto.Price;
            customerForUpdateBooking.numberOfClient    = customerForUpdateDto.numberOfClient;
            customerForUpdateBooking.RoomId            = customerForUpdateDto.RoomId;
            customerForUpdateBooking.numberOfFemale   += 1;

            // _mapper.Map(customerForUpdateDto,customerForUpdateBooking);

            if (await _repoForRoom.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Failed to Update booking");
        }
Пример #2
0
        public async Task <IActionResult> UpdateCustomer(int id, CustomerForUpdateDto[] customerInformationDto)
        {
            CustomerForUpdateDto oldCustomerInformationDto = customerInformationDto[0]; // first entry in body request is old customer info
            CustomerForUpdateDto newCustomerInformationDto = customerInformationDto[1]; // second entry is new customer info

            if (oldCustomerInformationDto == null || newCustomerInformationDto == null)
            {
                throw new Exception($"Error updating user {id} . Failed on information processing.");
            }

            // Checks that the id is for the currently logged in customer, otherwise unauthorized
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            // Maps the old customer information to a customers model
            Customers oldCustomer = new Customers();

            mapper.Map(oldCustomerInformationDto, oldCustomer);
            oldCustomer.CustomerId = id; // assign the customer id

            // Tries to save changes
            if (await repo.EditCustomer(oldCustomer, newCustomerInformationDto) != null)
            {
                return(NoContent());
            }

            // If unsuccessful, throw exception that we failed to save
            throw new Exception($"Updating user {id} failed on save");
        }
Пример #3
0
        public async Task <IActionResult> PutCustomer(int id, [FromBody] CustomerForUpdateDto customer)
        {
            try
            {
                if (customer == null)
                {
                    return(BadRequest("customer object is null"));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }
                var customerEntity = await _repo.GetCustomer(id);

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

                var customerToUpdate = _mapper.Map <Customer>(customer);

                _repo.UpdateCustomer(customerToUpdate);

                await _repo.SaveAll();

                return(Ok("Successfully updated"));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "Internal server error"));
            }
        }
Пример #4
0
        // Edits the customer given the old customer and new customer
        public async Task <Customers> EditCustomer(Customers oldCustomer, CustomerForUpdateDto newCustomer)
        {
            // Gets old customer from db, ensures that customer has not been changed (for updatable properties)
            var oldCustomerFromDB = await context.Customers
                                    .Where(c =>
                                           (c.CustomerId == oldCustomer.CustomerId) &&
                                           (c.CustAddress == oldCustomer.CustAddress) &&
                                           (c.CustCity == oldCustomer.CustCity) &&
                                           (c.CustCountry == oldCustomer.CustCountry) &&
                                           (c.CustFirstName == oldCustomer.CustFirstName) &&
                                           (c.CustLastName == oldCustomer.CustLastName) &&
                                           (c.CustPostal == oldCustomer.CustPostal) &&
                                           (c.CustProv == oldCustomer.CustProv) &&
                                           (c.CustHomePhone == oldCustomer.CustHomePhone) &&
                                           (c.CustBusPhone == oldCustomer.CustBusPhone) &&
                                           (c.CustEmail == oldCustomer.CustEmail)
                                           ).FirstOrDefaultAsync();

            if (oldCustomerFromDB != null)
            {
                mapper.Map(newCustomer, oldCustomerFromDB); // Assigns new customer properties to old customer
                await context.SaveChangesAsync();           // Saves changes
            }
            return(oldCustomerFromDB);                      // Returns updated customer from db
        }
Пример #5
0
        public IActionResult UpdateCustomer(Guid id, [FromBody] CustomerForUpdateDto customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (_talaCustomerRepository.ItemExists(id))
            {
                return(NotFound());
            }

            var customerFromRepo = _talaCustomerRepository.Get(id);

            Mapper.Map(customer, customerFromRepo);

            _talaCustomerRepository.Update(customerFromRepo);

            if (_talaCustomerRepository.Save())
            {
                throw new Exception($"Updating ustomer {id} failed on save.");
            }

            return(NoContent());
        }
        public async Task <IActionResult> UpdateCustomer([FromBody] CustomerForUpdateDto customerForUpdateDto)
        {
            var customer = _mapper.Map <Customer>(customerForUpdateDto);

            await _customerService.UpdateAsync(customer);

            return(Ok());
        }
        public async Task UpdateCustomer(CustomerForUpdateDto customerForUpdateDto)
        {
            //var customerToUpdateJson = new StringContent(
            //   JsonSerializer.Serialize(customerForUpdateDto, _options),
            //   Encoding.UTF8,
            //   "application/json");
            await _client.PutAsJsonAsync(Path.Combine("customers",
                                                      customerForUpdateDto.Id.ToString()), customerForUpdateDto);

            //using var product =
            //    await _client.PutAsync(Path.Combine("customers", customerForUpdateDto.Id.ToString()), customerForUpdateDto);
            _navManager.NavigateTo("/customers");
        }
Пример #8
0
        public async Task <IActionResult> UpdateCustomer(int id, CustomerForUpdateDto customerForUpdateDto)
        {
            var customerFromRepo = await _repo.GetCustomer(id);

            _mapper.Map(customerForUpdateDto, customerFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating user {id} failed on save");
        }
        public async Task <IActionResult> UpdateCustomer(int id, CustomerForUpdateDto customerForUpdate)
        {
            var customerFromRepo = await _context.Customers.Where(x => x.Id == id && x.IsActive == true).FirstOrDefaultAsync();

            _mapper.Map(customerForUpdate, customerFromRepo);
            customerFromRepo.LastUpdate    = DateTime.Now;
            customerFromRepo.LastUpdatedBy = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (await _context.SaveChangesAsync() > 0)
            {
                return(Ok("Update successfully."));
            }

            throw new System.Exception("Updating for customer failed on server.");
        }
        private async Task Update()
        {
            var customer = new CustomerForUpdateDto
            {
                Id        = _customerForUpdateDto.Id,
                FirstName = _customerForUpdateDto.FirstName,
                LastName  = _customerForUpdateDto.LastName,
                Email     = _customerForUpdateDto.Email
            };

            await CustomerRepository.UpdateCustomer(customer);

            ToastService.ShowSuccess($"Action successful. " +
                                     $"Product \"{_customerForUpdateDto.FirstName}\" successfully updated.");
            NavigationManager.NavigateTo("/customers");
        }
Пример #11
0
        public async Task <IActionResult> UpdateCustomer(Guid customerId, CustomerForUpdateDto customerToUpdate)
        {
            var customerFromRepo = _customersRepository.GetById(customerId);

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

            // can be upserting?

            _mapper.Map(customerToUpdate, customerFromRepo);
            await _customersRepository.SaveAsync();

            return(NoContent());
        }
        public async Task <IActionResult> UpdateCustomer(Guid id, [FromBody] CustomerForUpdateDto customerForUpdate)
        {
            var customer = HttpContext.Items["customer"] as Customer;

            customer.Name        = customerForUpdate.Name;
            customer.LastName    = customerForUpdate.LastName;
            customer.Age         = customerForUpdate.Age;
            customer.Gender      = customerForUpdate.Gender;
            customer.Email       = customerForUpdate.Email;
            customer.PhoneNumber = customerForUpdate.PhoneNumber;
            customer.Address     = customerForUpdate.Address;

            await _repository.SaveAsync();

            return(NoContent());
        }
        public async Task <IActionResult> UpdateCustomer(int id, [FromBody] CustomerForUpdateDto customer)
        {
            if (customer == null)
            {
                _logger.LogError($"CustomerForCreationDto object sent from client is null. ");
                return(BadRequest("CustomerForCreationDto object is null"));
            }
            var customerEntity = await _serviceManager.Customer.GetCustomerAsync(id, trackChanges : false);

            if (customerEntity == null)
            {
                _logger.LogInfo($"Customer with id: {id} doesn't exist in the database.");
                return(NotFound());
            }
            _mapper.Map(customer, customerEntity);
            _serviceManager.Customer.UpdateCustomer(customerEntity);
            _serviceManager.Save();
            return(NoContent());
        }
        public async Task <IActionResult> UpdateCustomer(int id, [FromBody] CustomerForUpdateDto customerForUpdateDto)
        {
            if (customerForUpdateDto == null)
            {
                return(BadRequest());
            }

            var customer = await _repository.GetCustomerAsync(id);

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

            _mapper.Map(customerForUpdateDto, customer);

            await _unitOfWork.CompleteAsync();

            return(NoContent());
        }
Пример #15
0
        public async Task <IActionResult> UpdateCustomer(int id, [FromBody] CustomerForUpdateDto customer)
        {
            var customerEntity = HttpContext.Items["entity"] as Customer;

            if (!string.IsNullOrEmpty(customer.password))
            {
                AuthExtensions.CreatePasswordHash(customer.password, out byte[] passwordHash, out byte[] passwordSalt);
                customer.passwordHash = passwordHash;
                customer.passwordSalt = passwordSalt;
            }
            else
            {
                customer.passwordHash = customerEntity.passwordHash;
                customer.passwordSalt = customerEntity.passwordSalt;
            }

            _mapper.Map(customer, customerEntity);

            _repository.Customer.UpdateCustomer(customerEntity);
            await _repository.SaveAsync();

            return(NoContent());
        }