public async Task <IResponseModel> AddProductAsync(IAddProductModel model) { try { var product = new Product { Id = Guid.NewGuid(), Name = model.Name, IsDeleted = false, CategoryId = model.CategoryId, UserId = model.UserId }; _db.Products.Add(product); await _db.SaveChangesAsync(); _response.Status = true; _response.Message = "Product successfully added."; return(_response); } catch (Exception ex) { _response.Status = false; _response.Message = "Error adding product."; return(_response); } }
public async Task <IResponseModel> UpdateProductAsync(IAddProductModel model) { try { _db.Update(new Product { Name = model.Name, Description = model.Description, Image = model.Image, CategoryId = model.CategoryId }); await _db.SaveChangesAsync(); _response.Status = true; _response.Message = "Product successfully updated."; return(_response); } catch (Exception ex) { _response.Status = false; _response.Message = "Error updating Product."; return(_response); } }
public async Task <IActionResult> PutProductAsync([FromBody] IAddProductModel obj) { var isProdUpdated = await _productService.UpdateProductAsync(obj); _response.Status = isProdUpdated.Status ? true : false; _response.Message = isProdUpdated.Status ? "Product info updated" : "Error updating product"; if (_response.Status) { return(Ok(_response)); } else { return(BadRequest(_response)); } }
/// <summary> /// Constructor. /// </summary> /// <param name="model">Model</param> /// <param name="commonDialogService">Common dialog service</param> public AddProductViewModel(IAddProductModel model, ICommonDialogService commonDialogService) : base(model) { this.model = model; this.commonDialogService = commonDialogService; // properties this.Name = this.model.ToReactivePropertyAsSynchronized(myModel => myModel.Name) .AddTo(this.Disposable); this.IconPath = this.model.ToReactivePropertyAsSynchronized(myModel => myModel.IconPath) .AddTo(this.Disposable); this.Icon = this.model.ObserveProperty(myModel => myModel.Icon).ToReadOnlyReactivePropertySlim() .AddTo(this.Disposable); this.Path = this.model.ToReactivePropertyAsSynchronized(myModel => myModel.Path) .AddTo(this.Disposable); // commands this.SelectIconAsyncCommand = new[] { this.IsBusy.Select(isBusy => !isBusy), }.CombineLatest(combined => combined.All(condition => condition)).ToAsyncReactiveCommand() .AddTo(this.Disposable); this.SelectIconAsyncCommand.Subscribe(this.SelectIconAsync); this.SelectFileAsyncCommand = new[] { this.IsBusy.Select(isBusy => !isBusy), }.CombineLatest(combined => combined.All(condition => condition)).ToAsyncReactiveCommand() .AddTo(this.Disposable); this.SelectFileAsyncCommand.Subscribe(this.SelectFileAsync); this.AddProductAsyncCommand = new[] { this.IsBusy.Select(isBusy => !isBusy), this.Name.Select(name => !string.IsNullOrWhiteSpace(name)), this.Path.Select(path => !string.IsNullOrWhiteSpace(path)), }.CombineLatest(combined => combined.All(condition => condition)).ToAsyncReactiveCommand() .AddTo(this.Disposable); this.AddProductAsyncCommand.Subscribe(this.AddProductAsync); this.CancelCommand = new[] { this.IsBusy.Select(isBusy => !isBusy), }.CombineLatest(combined => combined.All(condition => condition)).ToReactiveCommand() .AddTo(this.Disposable); this.CancelCommand.Subscribe(this.Cancel); }
public async Task <IActionResult> PostAddProductAsync([FromBody] IAddProductModel obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var isAdded = await _productService.AddProductAsync(obj); _response.Status = isAdded.Status; _response.Message = isAdded.Message; if (_response.Status) { return(Ok(_response)); } else { return(BadRequest(_response)); } }
public async Task <IResponseModel> UpdateProductAsync(IAddProductModel model) => await _productRepo.UpdateProductAsync(model);