예제 #1
0
        public void Execute(RegisterUserDto request)
        {
            _validator.ValidateAndThrow(request);
            var user = _mapper.Map <User>(request);

            _context.Users.Add(user);

            _context.SaveChanges();
            int        id           = user.Id;
            List <int> listUseCases = new List <int> {
                12, 16, 13, 8, 25, 9, 15, 14, 33, 34, 35, 36
            };

            foreach (int useCase in listUseCases)
            {
                _context.UserUseCases.Add(new UserUseCase
                {
                    UserId    = id,
                    UseCaseId = useCase
                });
            }
            _context.SaveChanges();

            _sender.Send(new SendEmailDto
            {
                Content = "<h1>Successfull registration!</h1>",
                SendTo  = request.Email,
                Subject = "Registration"
            });
        }
        public void Execute(UserUseCaseDto request)
        {
            var userUserCase = _mapper.Map <UserUseCase>(request);

            _context.UserUseCases.Add(userUserCase);
            _context.SaveChanges();
        }
        public void Execute(OrderDto request)
        {
            int userId = _actor.Id;

            request.Address = _context.Users.Find(userId).Address;
            request.UserId  = userId;
            foreach (OrderItemDto item in request.OrderItems)
            {
                item.Price = item.Quantity * _context.Perfumes.Find(item.PerfumeId).Price;
                var perfumeCart = _context.Carts.Where(x => (x.PerfumeId == item.PerfumeId) && (x.UserId == userId)).FirstOrDefault();
                if (perfumeCart is Cart)
                {
                    perfumeCart.IsDeleted = true;
                    perfumeCart.DeletedAt = DateTime.Now;
                    perfumeCart.IsActive  = false;
                }
                var perfume = _context.Perfumes.Find(item.PerfumeId);
                perfume.NumberOfAvailable = perfume.NumberOfAvailable - item.Quantity;
            }

            var order = _mapper.Map <Order>(request);

            _context.Add(order);
            _context.SaveChanges();
        }
        public void Execute(UpdatePerfumeDto request)
        {
            _validator.ValidateAndThrow(request);
            var perfume = _context.Perfumes.Find(request.Id);

            if (perfume == null)
            {
                throw new KeyNotFoundException();
            }
            if (request.Image != null)
            {
                perfume.Image = request.Image;
            }
            if (request.IsActive != null)
            {
                perfume.IsActive = (bool)request.IsActive;
            }
            if (request.Price != null)
            {
                perfume.Price = (decimal)request.Price;
            }
            if (request.Discount != null)
            {
                perfume.Discount = (int)request.Discount;
            }
            if (request.NumberOfAvailable != null)
            {
                perfume.NumberOfAvailable = (int)request.NumberOfAvailable;
            }
            perfume.ModifiedAt = DateTime.Now;
            _context.SaveChanges();
        }
        public void Execute(InsertBrandDto request)
        {
            _validator.ValidateAndThrow(request);
            var brand = _mapper.Map <Brand>(request);

            _context.Brands.Add(brand);
            _context.SaveChanges();
        }
예제 #6
0
        public void Execute(AddInCartDto request)
        {
            _validator.ValidateAndThrow(request);
            request.UserId = _actor.Id;
            var cart = _mapper.Map <Cart>(request);

            _context.Carts.Add(cart);
            _context.SaveChanges();
        }
        public void Execute(CreatePerfumeDto request)
        {
            _validator.ValidateAndThrow(request);

            var perfume = _mapper.Map <Perfume>(request);

            _context.Perfumes.Add(perfume);
            _context.SaveChanges();
        }
        public void Execute(UserUseCaseDeleteDto request)
        {
            var useCase = _context.UserUseCases.Where(x => (x.UseCaseId == request.UseCaseId) && (x.UserId == request.UserId)).FirstOrDefault();

            if (useCase == null)
            {
                throw new KeyNotFoundException();
            }
            _context.UserUseCases.Remove(useCase);
            _context.SaveChanges();
        }
예제 #9
0
        public void Execute(int id)
        {
            var perfume = _context.Perfumes.Find(id);

            if (perfume == null)
            {
                throw new EntityNotFoundException(id, typeof(Perfume));
            }
            perfume.DeletedAt = DateTime.Now;
            perfume.IsDeleted = true;
            perfume.IsActive  = false;
            _context.SaveChanges();
        }
        public void Execute(int id)
        {
            var cart = _context.Carts.Find(id);

            if (cart == null)
            {
                throw new EntityNotFoundException(id, typeof(Cart));
            }
            cart.IsDeleted = true;
            cart.DeletedAt = DateTime.Now;
            cart.IsActive  = false;
            _context.SaveChanges();
        }
예제 #11
0
        public void Execute(CartDto request)
        {
            _validator.ValidateAndThrow(request);

            int userId = _actor.Id;

            var cart = _context.Carts.Where(x => x.PerfumeId == (request.PerfumeId) && (x.UserId == userId)).FirstOrDefault();

            cart.Quantity   = request.Quantity;
            cart.ModifiedAt = DateTime.Now;
            if (request.Quantity < 1)
            {
                cart.IsDeleted = true;
                cart.DeletedAt = DateTime.Now;
                cart.IsActive  = false;
            }
            _context.SaveChanges();
        }
예제 #12
0
        public void Execute(BrandDto request)
        {
            _validator.ValidateAndThrow(request);
            var brand = _context.Brands.Find(request.Id);

            if (request.Name != null)
            {
                brand.Name = request.Name;
            }
            if (request.IsActive != null)
            {
                brand.IsActive = (bool)request.IsActive;
            }
            if (request.Description != null)
            {
                brand.Description = request.Description;
            }
            brand.ModifiedAt = DateTime.Now;
            _context.SaveChanges();
        }
예제 #13
0
        public void Execute(int request)
        {
            var brand = _context.Brands.Find(request);

            if (brand == null)
            {
                throw new EntityNotFoundException(request, typeof(Brand));
            }
            brand.DeletedAt = DateTime.Now;
            brand.IsDeleted = true;
            brand.IsActive  = false;

            var perfumes = _context.Perfumes.Where(x => x.BrandId == brand.Id).ToList();

            foreach (var perfume in perfumes)
            {
                perfume.IsDeleted = true;
                perfume.IsActive  = false;
                perfume.DeletedAt = DateTime.Now;
            }
            _context.SaveChanges();
        }
예제 #14
0
        public IActionResult create(string submit, string cancel, Perfume perfume)
        {
            var button = submit ?? cancel;

            if (button == "Cancel")
            {
                return(RedirectToAction("Index"));
            }

            if (db.Perfumes.Contains(perfume))
            {
                return(BadRequest());
            }

            db.Perfumes.Add(perfume);
            db.SaveChanges();
            return(View(db.Perfumes.ToList()));
        }
예제 #15
0
        public static void Initialize(PerfumeContext context)
        {
            if (!context.Brands.Any())
            {
                context.Brands.AddRange(
                    new Brand
                {
                    Name    = "Chanel",
                    Country = "France"
                },
                    new Brand
                {
                    Name    = "Eclat d’Arpege",
                    Country = "France"
                },
                    new Brand
                {
                    Name    = "Lanvin",
                    Country = "France"
                },
                    new Brand
                {
                    Name    = "Armani",
                    Country = "Italy"
                },
                    new Brand
                {
                    Name    = "Versace",
                    Country = "Italy"
                },
                    new Brand
                {
                    Name    = "Givenchy",
                    Country = "France"
                },
                    new Brand
                {
                    Name    = "Burberry",
                    Country = "UK"
                },
                    new Brand
                {
                    Name    = "Kenzo",
                    Country = "French"
                }
                    );
                context.SaveChanges();
            }

            if (!context.Perfumes.Any())
            {
                context.Perfumes.AddRange(
                    new Perfume
                {
                    Name   = "Eclat d’Arpege",
                    Price  = 1500,
                    Count  = 10,
                    Volume = 30,
                    Brand  = "Chanel"
                },
                    new Perfume
                {
                    Name   = "Coco Mademoiselle",
                    Price  = 6000,
                    Count  = 50,
                    Volume = 50,
                    Brand  = "Lanvin"
                },
                    new Perfume
                {
                    Name   = "Acqua di Gioia",
                    Price  = 4700,
                    Count  = 15,
                    Volume = 50,
                    Brand  = "Armani"
                },
                    new Perfume
                {
                    Name   = "Bright Crystal",
                    Price  = 4000,
                    Count  = 10,
                    Volume = 50,
                    Brand  = "Versace"
                },
                    new Perfume
                {
                    Name   = "Very Irresistible",
                    Price  = 4500,
                    Count  = 15,
                    Volume = 50,
                    Brand  = "Givenchy"
                },
                    new Perfume
                {
                    Name   = "Chance Eau Tendre",
                    Price  = 7400,
                    Count  = 15,
                    Volume = 50,
                    Brand  = "Chanel"
                },
                    new Perfume
                {
                    Name   = "Body Tender",
                    Price  = 2500,
                    Count  = 15,
                    Volume = 60,
                    Brand  = "Burberry"
                },
                    new Perfume
                {
                    Name   = "L'eau par",
                    Price  = 2400,
                    Count  = 15,
                    Volume = 50,
                    Brand  = "Kenzo"
                }
                    );
                context.SaveChanges();
            }
        }