public async Task <Unit> Handle(CreateProducteVm request, CancellationToken cancellationToken) { var Category = await context_.Categories.FindAsync(request.CategoryName); var User = await manager_.FindByIdAsync(request.AppUserId); if (Category != null) { if (User != null) { var Product = new Product() { AppUser = User, AppUserId = User.Id, CategoryId = Category.Id, Name = request.Name, Picture = request.Picture, Price = request.Price, Description = request.Description, Category = Category, Availability = request.Availability }; await context_.Products.AddAsync(Product); await context_.SaveChangesAsync(cancellationToken); } } return(Unit.Value); }
public async Task <Unit> Handle(DeleteCharacteristicVm request, CancellationToken cancellationToken) { var Characteristic = await context_.Characteristics.FindAsync(request.Name); if (Characteristic != null) { context_.Characteristics.Remove(Characteristic); await context_.SaveChangesAsync(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(DeleteContactVm request, CancellationToken cancellationToken) { var Contact = await context_.Сontacts.FindAsync(request.Id); if (Contact != null) { context_.Сontacts.Remove(Contact); await context_.SaveChangesAsync(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(EditContactVm request, CancellationToken cancellationToken) { var oldContact = await context_.Сontacts.FindAsync(request.Id); if (oldContact != null) { oldContact.Name = request.Name; oldContact.Url = request.Url; context_.Сontacts.Update(oldContact); await context_.SaveChangesAsync(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(EditCharacteristicVm request, CancellationToken cancellationToken) { var oldCharacteristic = await context_.Characteristics.FindAsync(request.Name); if (oldCharacteristic != null) { oldCharacteristic.Name = request.Name; oldCharacteristic.Value = request.Value; context_.Characteristics.Update(oldCharacteristic); await context_.SaveChangesAsync(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(CreateCharacteristicVm request, CancellationToken cancellationToken) { if (request.Name != null) { if (request.Value != null) { var Characteristic = new Characteristic() { Name = request.Name, Value = request.Value }; await context_.Characteristics.AddAsync(Characteristic); await context_.SaveChangesAsync(cancellationToken); } } return(Unit.Value); }
public async Task <Unit> Handle(CreateContactVm request, CancellationToken cancellationToken) { var User = await manager_.FindByIdAsync(request.AppUserId); if (User != null) { var Contact = new Сontact() { AppUser = User, AppUserId = User.Id, Name = request.Name, Url = request.Url }; await context_.Сontacts.AddAsync(Contact); await context_.SaveChangesAsync(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(EditProductVm request, CancellationToken cancellationToken) { var Category = await context_.Categories.FindAsync(request.CategoryName); var oldProduct = await context_.Products.FindAsync(request.Id); if (oldProduct != null) { if (Category != null) { oldProduct.Name = request.Name; oldProduct.Category = Category; oldProduct.Description = request.Description; oldProduct.Price = request.Price; oldProduct.Picture = request.Picture; oldProduct.Availability = request.Availability; context_.Products.Update(oldProduct); await context_.SaveChangesAsync(cancellationToken); } } return(Unit.Value); }