public async Task <IHttpActionResult> UpdateOption(Guid id, ProductOptionApiModel option) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id == Guid.Empty) { return(BadRequest("The id cannot be empty!")); } option.Id = id; try { var result = await _productOptionServices.UpdateAsync(AutoMapper.Mapper.Map <ProductOptionDto>(option)); return(Ok(AutoMapper.Mapper.Map <ProductOptionApiModel>(result))); } catch (EntityNotFoundException) { return(NotFound()); } catch (DbUpdateConcurrencyException) { return(Conflict()); } catch (Exception) { throw; } }
public async Task <IHttpActionResult> CreateOption(Guid productId, ProductOptionApiModel option) { option.ProductId = productId; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _productOptionServices.CreateAsync(AutoMapper.Mapper.Map <ProductOptionDto>(option)); return(CreatedAtRoute("DefaultApi", new { id = result.Id }, AutoMapper.Mapper.Map <ProductOptionApiModel>(result))); }
public async Task <ProductOptionApiModel> CreateAsync(ProductOptionApiModel option) { // Transaction is being used here just as an example (let's consider that more than one operation could happen below) this.BeginTransaction(); var newOption = await this._productOptionService.CreateAsync(option.Adapt <ProductOption>()); this.Commit(); return(newOption.Adapt <ProductOptionApiModel>()); }
public async Task <IHttpActionResult> UpdateOption(Guid productId, ProductOptionApiModel option) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } if (await this._productOptionAppService.GetByIdAsync(productId, option.Id) == null) { return(this.NotFound()); } option.Id = productId; await this._productOptionAppService.UpdateAsync(option); return(this.Ok()); }
public async Task <IHttpActionResult> CreateOption(Guid productId, ProductOptionApiModel option) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } if (await this._productOptionAppService.GetByIdAsync(productId, option.Id) != null) { return(this.Conflict()); } option.ProductId = productId; var newOption = await this._productOptionAppService.CreateAsync(option); return(this.CreatedAtRoute("GetOptionById", new { productId = newOption.ProductId, id = newOption.Id }, newOption)); }
public async Task RemoveAsync(ProductOptionApiModel option) { await this._productOptionService.RemoveAsync(option.Adapt <ProductOption>()); }