// [ValidateAntiForgeryToken] public HttpResponseMessage EditProduct([FromBody] CreateDataModel DataModel) { var service = new ProductService(); if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } service.Edit(DataModel); return(new HttpResponseMessage(HttpStatusCode.OK)); }
//trycatch public OperationResult Create(CreateDataModel input) { var result = new OperationResult(); try { XbooxLibraryDBContext context = new XbooxLibraryDBContext(); GeneralRepository <Product> repository = new GeneralRepository <Product>(context); //tag && img Product entity = new Product() { ProductId = Guid.NewGuid(), Name = input.Name, CategoryId = input.CategoryId, ISBN = input.ISBN, Author = input.Author, Specification = input.Specification, Intro = input.Intro, Language = input.Language, UnitInStock = input.UnitInStock, PublishedDate = input.PublishedDate, Description = input.Description, Price = input.Price }; PutImgs(entity); //加入Img repository.Create(entity); repository.SaveContext(); //加入tag AddedTag(entity, input.PostedTagIds); //context.SaveChanges(); // repository.SaveContext(); result.IsSuccessful = true; } catch (Exception ex) { result.IsSuccessful = false; result.exception = ex; } return(result); }
public IActionResult GetDetails() { CreateDataModel umodel = new CreateDataModel(); umodel.companyId = Convert.ToInt32(HttpContext.Request.Form["txtCompanyId"]); umodel.topic = HttpContext.Request.Form["txtTopic"].ToString(); umodel.degree = HttpContext.Request.Form["txtDegree"].ToString(); umodel.description = HttpContext.Request.Form["txtDescription"].ToString(); int result = umodel.SaveDetails(); if (result > 0) { ViewBag.Result = "Data Saved Successfully"; } else { ViewBag.Result = "Something Went Wrong"; } return(View("Index")); }
public OperationResult Edit(CreateDataModel input) { var result = new OperationResult(); XbooxLibraryDBContext context = new XbooxLibraryDBContext(); GeneralRepository <Product> repository = new GeneralRepository <Product>(context); try { var productInDb = repository.GetFirst(p => p.ProductId == input.ProductId); productInDb.Name = input.Name; productInDb.CategoryId = input.CategoryId; productInDb.ISBN = input.ISBN; productInDb.Author = input.Author; productInDb.Specification = input.Specification; productInDb.Intro = input.Intro; productInDb.Language = input.Language; productInDb.UnitInStock = input.UnitInStock; productInDb.PublishedDate = input.PublishedDate; productInDb.Description = input.Description; PutImgs(productInDb); //加入Img productInDb.ProductImgId = input.ProductImgId; repository.Update(productInDb); repository.SaveContext(); //加入tag AddedTag(productInDb, input.PostedTagIds); // context.SaveChanges(); result.IsSuccessful = true; } catch (Exception ex) { result.IsSuccessful = false; result.exception = ex; } return(result); }
public async Task <IActionResult> CreateAsync([FromBody] CreateDataModel model) { var dto = await _service.CreateAsync(_mapper.Map <DataDTO>(model)); return(Ok(_mapper.Map <DataViewModel>(dto))); }