public void Execute(int id, UpdateUserDto dto) { dto.Id = id; var user = _context.Users.Find(id); if (user == null) { throw new EntityNotFoundException(id, typeof(User)); } _validator.ValidateAndThrow(dto); /*_mapper.Map(dto, user);*/ user.FirstName = dto.FirstName; user.LastName = dto.LastName; user.Password = dto.Password; user.Email = dto.Email; user.UserUseCases = dto.UserUseCases.Select(u => new UserUseCase { UseCaseId = u.UseCaseId }).ToList(); _context.SaveChanges(); }
public void Execute(CreateOrderDto dto) { _validator.ValidateAndThrow(dto); var order = new Order { UserId = dto.Id, Address = dto.Address, OrderDate = dto.OrderDate }; foreach (var item in dto.Items) { var product = _context.Products.Find(item.ProductId); product.Quantity -= item.Quantity; order.OrderLines.Add(new OrderLine { ProductId = item.ProductId, Quantity = item.Quantity, Name = product.Name, Price = product.Price }); } _context.Orders.Add(order); _context.SaveChanges(); }
public void Execute(UserDto request) { _validator.ValidateAndThrow(request); var user = new User { FirstName = request.FirstName, LastName = request.LastName, Username = request.Username, Password = request.Password, Email = request.Email }; _context.Users.Add(user); _context.SaveChanges(); var a = _context.Users.Where(x => x.Username == request.Username).FirstOrDefault(); var permits = new List <int> { 4, 10, 16, 18, 8, 1, 17, 14, 15, 19, 21 }; foreach (var permit in permits) { _context.UserUseCases.Add(new UserUseCase { UserId = a.Id, UseCaseId = permit }); } _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Successful registration!</h1>", SendTo = request.Email, Subject = "Registration" }); }
public void Execute(ProductDto request) { _validator.ValidateAndThrow(request); var result = _mapper.Map <Product>(request); _context.Products.Add(result); _context.SaveChanges(); }
public void Log(IUseCase useCase, IApplicationActor actor, object UseCaseData) { _context.UseCaseLogs.Add(new Domain.UseCaseLog { Actor = actor.Identity, Date = DateTime.UtcNow, UseCaseName = useCase.Name, Data = JsonConvert.SerializeObject(UseCaseData) }); _context.SaveChanges(); }
public void Execute(BrandDto request) { _validator.ValidateAndThrow(request); var brand = new Brand { Name = request.Name }; _context.Brands.Add(brand); _context.SaveChanges(); }
public void Execute(int id, CreateOrderDto dto) { dto.Id = id; var order = _context.Orders .Include(x => x.User) .Include(o => o.OrderLines).FirstOrDefault(o => o.Id == id); if (order == null) { throw new EntityNotFoundException(id, typeof(Order)); } _validator.ValidateAndThrow(dto); foreach (var or in order.OrderLines) { var pr = _context.Products.Find(or.ProductId); var stari = order.OrderLines.FirstOrDefault(x => x.ProductId == or.ProductId); pr.Quantity += stari.Quantity; or.IsActive = false; or.IsDeleted = true; or.DeletedAt = DateTime.Now; } order.Address = dto.Address; order.OrderDate = dto.OrderDate; foreach (var item in dto.Items) { var product = _context.Products.Find(item.ProductId); product.Quantity -= item.Quantity; order.OrderLines.Add(new OrderLine { ProductId = item.ProductId, Quantity = item.Quantity, Name = product.Name, Price = product.Price }); } _context.SaveChanges(); }
public void Execute(int request) { var product = _context.Products.Find(request); if (product == null) { throw new EntityNotFoundException(request, typeof(Product)); } product.IsActive = false; product.IsDeleted = true; product.DeletedAt = DateTime.Now; _context.SaveChanges(); }
public void Execute(int request) { var brand = _context.Brands.Find(request); if (brand == null) { throw new EntityNotFoundException(request, typeof(Brand)); } brand.IsActive = false; brand.IsDeleted = true; brand.DeletedAt = DateTime.Now; _context.SaveChanges(); }
public void Execute(int request) { var order = _context.Orders.Find(request); if (order == null) { throw new EntityNotFoundException(request, typeof(Order)); } order.IsActive = false; order.IsDeleted = true; order.DeletedAt = DateTime.Now; _context.SaveChanges(); }
public void Execute(CommentDto request) { _validator.ValidateAndThrow(request); var comment = new Comment { Text = request.Text, ProductId = request.ProductId, UserId = request.UserId }; _context.Comments.Add(comment); _context.SaveChanges(); }
public void Execute(int request) { var comment = _context.Comments.Find(request); if (comment == null) { throw new EntityNotFoundException(request, typeof(Comment)); } comment.IsActive = false; comment.IsDeleted = true; comment.DeletedAt = DateTime.Now; _context.SaveChanges(); }
public void Execute(int id, ProductDto dto) { dto.Id = id; var product = _context.Products.Find(id); if (product == null) { throw new EntityNotFoundException(id, typeof(Product)); } _validator.ValidateAndThrow(dto); _mapper.Map(dto, product); _context.SaveChanges(); }
public void Execute(int id, BrandDto dto) { dto.Id = id; var brand = _context.Brands.Find(id); if (brand == null) { throw new EntityNotFoundException(id, typeof(Brand)); } _validator.ValidateAndThrow(dto); brand.Name = dto.Name; _context.SaveChanges(); }
public void Execute(int id, CommentDto dto) { dto.Id = id; var comment = _context.Comments.Find(id); if (comment == null) { throw new EntityNotFoundException(id, typeof(Comment)); } _validator.ValidateAndThrow(dto); comment.Text = dto.Text; comment.ProductId = dto.ProductId; comment.UserId = dto.UserId; _context.SaveChanges(); }