Example #1
0
        public async Task UpdateCustomerAsync(UserShortDTO userDTO)
        {
            var customer = await _unitOfWork.CustomerRepository.GetByIdAsync(userDTO.Id);

            if (customer != null)
            {
                customer.Person.Name             = userDTO.Name;
                customer.Person.Surname          = userDTO.SurName;
                customer.Person.MiddleName       = userDTO.MiddleName;
                customer.Person.Account.Email    = userDTO.Email;
                customer.Person.Phone            = userDTO.Phone;
                customer.Person.Birthday         = userDTO.Birthday;
                customer.Person.Account.Location = new Location()
                {
                    Adress    = userDTO.Location.Adress,
                    City      = userDTO.Location.City,
                    IsDeleted = false,
                    Latitude  = userDTO.Location.Latitude,
                    Longitude = userDTO.Location.Longitude,
                    PostIndex = userDTO.Location.PostIndex
                };
                _unitOfWork.CustomerRepository.Update(customer);
                await _unitOfWork.SaveAsync();
            }
        }
Example #2
0
        public async Task <HttpResponseMessage> UpdateCustomerAsync(long id, [FromBody] UserShortDTO userDTO)
        {
            await _customerService.UpdateCustomerAsync(userDTO);

            var result = await _customerService.GetById(id);

            if (result == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
        public async Task <object> GetCustomerAsync(long id)
        {
            var customer = await _unitOfWork.CustomerRepository.
                           Query.Include(c => c.History.Select(h => h.Vendor.Person)).
                           Include(c => c.Books.Select(h => h.Vendor.Person)).
                           Include(c => c.Person.Account.Location).
                           SingleAsync(c => c.Id == id);

            if (customer != null)
            {
                var customerDto = new UserShortDTO()
                {
                    Id         = customer.Id,
                    AccountId  = customer.Person.Account.Id,
                    Name       = customer.Person.Name,
                    SurName    = customer.Person.Surname,
                    MiddleName = customer.Person.MiddleName,
                    Location   = new LocationDTO()
                    {
                        Adress    = customer.Person.Account.Location.Adress,
                        City      = customer.Person.Account.Location.City,
                        Latitude  = customer.Person.Account.Location.Latitude,
                        Longitude = customer.Person.Account.Location.Longitude,
                        PostIndex = customer.Person.Account.Location.PostIndex
                    },
                    DateCreated   = customer.Person.Account.DateCreated,
                    Birthday      = customer.Person.Birthday,
                    Phone         = customer.Person.Phone,
                    Avatar        = customer.Person.Account.Avatar,
                    CroppedAvatar = customer.Person.Account.CroppedAvatar,
                    Background    = customer.Person.Account.Background,
                    Email         = customer.Person.Account.Email,
                    History       = customer.History.Select(x => new HistoryShortDto()
                    {
                        bookDescription = x.BookDescription,
                        categoryName    = x.CategoryName,
                        date            = x.Date,
                        dateFinished    = x.DateFinished,
                        subcategoryName = x.SubcategoryName,
                        vendor          = x?.Vendor?.Person?.Name,
                        workDescription = x.WorkDescription
                    }).ToList()
                };

                return(customerDto);
            }

            return(null);
        }