public async Task <IHttpActionResult> PutCategoriesNew(CategoriesNew categoriesNew) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var item = await db.CategoriesNews.FindAsync(categoriesNew.Id); if (item == null) { return(NotFound()); } item.Published = categoriesNew.Published; item.Name = categoriesNew.Name; item.Description = categoriesNew.Description; item.UnsignName = Common.Utils.Ucs2Convert(categoriesNew.Name); db.Entry(item).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult New(CategoriesNew categoriesNew, int?ID) { if (Database.Session.Query <Category>().Any(x => (x.CategoryName.Equals(categoriesNew.CategoryName)) && (x.ID != ID))) { ModelState.AddModelError("", "Kategori adı kullanılıyor"); } if (!ModelState.IsValid) { return(View(categoriesNew)); } Category category = new Category { CategoryName = categoriesNew.CategoryName, }; if (ID == null) { Database.Session.Save(category); } else { category.ID = (int)ID; Database.Session.Update(category); } return(RedirectToAction("Index")); }
public async Task <IHttpActionResult> GetCategoriesNew(int id) { CategoriesNew categoriesNew = await db.CategoriesNews.FindAsync(id); if (categoriesNew == null) { return(NotFound()); } return(Ok(categoriesNew)); }
public async Task <IHttpActionResult> DeleteCategoriesNew(int id) { CategoriesNew categoriesNew = await db.CategoriesNews.FindAsync(id); if (categoriesNew == null) { return(NotFound()); } db.CategoriesNews.Remove(categoriesNew); await db.SaveChangesAsync(); return(Ok(categoriesNew)); }
public async Task <IHttpActionResult> PostCategoriesNew(CategoriesNew categoriesNew) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } categoriesNew.Published = true; categoriesNew.CreatedOnUtc = DateTime.Now; categoriesNew.UpdatedOnUtc = DateTime.Now; categoriesNew.UnsignName = Common.Utils.Ucs2Convert(categoriesNew.Name); db.CategoriesNews.Add(categoriesNew); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = categoriesNew.Id }, categoriesNew)); }
public ActionResult New(int?ID) { if (ID != null) { Category category = Database.Session.Get <Category>(ID); if (category != null) { CategoriesNew categoriesNew = new CategoriesNew { CategoryName = category.CategoryName }; return(View(categoriesNew)); } } return(View(new CategoriesNew())); }