예제 #1
0
        public async Task <bool> Update(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var exsistedUser = await _context.Users
                               .FirstOrDefaultAsync(f => f.Id == user.Id);

            if (exsistedUser == null)
            {
                throw new ArgumentNullException(nameof(exsistedUser));
            }

            _context.Entry(exsistedUser).State = EntityState.Modified;

            exsistedUser.Name            = user.Name;
            exsistedUser.SecondName      = user.SecondName;
            exsistedUser.PhoneNumber     = user.PhoneNumber;
            exsistedUser.Email           = user.Email;
            exsistedUser.NormalizedEmail = user.Email.ToUpper();
            exsistedUser.PasswordHash    = user.PasswordHash;
            exsistedUser.UserName        = user.Name;

            await _context.SaveChangesAsync();

            return(true);
        }
예제 #2
0
        public async Task <bool> Update(ProductCard productCard)
        {
            if (productCard == null)
            {
                throw new ArgumentNullException(nameof(productCard));
            }

            var existedProductCard = await _context.ProductCards
                                     .FirstOrDefaultAsync(f => f.Id == productCard.Id);

            if (existedProductCard == null)
            {
                throw new ArgumentNullException(nameof(existedProductCard));
            }

            _context.Entry(existedProductCard).State = EntityState.Modified;

            existedProductCard.DateCreated = productCard.DateCreated;
            existedProductCard.Quantity    = productCard.Quantity;

            await _context.SaveChangesAsync();

            return(true);
        }
예제 #3
0
        public async Task <bool> Add(Basket newBasket)
        {
            if (newBasket == null)
            {
                throw new ArgumentNullException(nameof(newBasket));
            }

            var basket = _mapper.Map <Core.CoreModels.Basket, Entities.Basket>(newBasket);

            var result = await _context.Baskets.AddAsync(basket);

            if (result.State != EntityState.Added)
            {
                return(false);
            }

            await _context.SaveChangesAsync();

            return(true);
        }