public ActionResult AddCatergory(string catergoryName) { try { using (ESamhashoEntities entities = new ESamhashoEntities()) { Catergory catergory = new Catergory { IsDeleted = false, Name = catergoryName, DateCreated = DateTime.Now, DateModified = DateTime.Now }; entities.Catergories.Add(catergory); entities.SaveChanges(); return(new ActionResult { Success = true, Message = catergory.Id.ToString() }); } } catch (Exception exception) { Dictionary <string, string> dictionary = new Dictionary <string, string> { { "catergoryName", catergoryName } }; ServiceHelper.LogException(exception, dictionary, ErrorSource.Catergory); return(new ActionResult { Message = "Error, catergory failed to save, try again." }); } }
public ActionResult DeleteConfirmed(int id) { Catergory catergory = db.Catergories.Find(id); db.Catergories.Remove(catergory); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <JsonResult> AddCategory([FromBody] CategoryView model) { Catergory catergory = new Catergory { CategoryName = model.CategoryName }; await _categoryRepository.AddRecordyAsync(catergory); return(Json("success")); }
public ActionResult Edit([Bind(Include = "Id,Name")] Catergory catergory) { if (ModelState.IsValid) { db.Entry(catergory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(catergory)); }
public ActionResult DeleteConfirmed(int id) { Catergory catergory = catManager.Find(x => x.Id == id); catManager.Delete(catergory); CacheHelper.RemoveCategoriesFromCache(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,Name")] Catergory catergory) { if (ModelState.IsValid) { db.Catergories.Add(catergory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(catergory)); }
public async Task <IActionResult> DeleteCategory(string CategoryID) { if (!string.IsNullOrEmpty(CategoryID)) { Catergory catergory = await _categoryRepository.FindByIdAsync(CategoryID); if (catergory != null) { return(PartialView("DeleteCategory", catergory)); } } return(PartialView("DeleteCategory")); }
// GET: Catergories/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Catergory catergory = db.Catergories.Find(id); if (catergory == null) { return(HttpNotFound()); } return(View(catergory)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Catergory catergory = catManager.Find(x => x.Id == id.Value); if (catergory == null) { return(HttpNotFound()); } return(View(catergory)); }
public ActionResult Create(Catergory catergory) { ModelState.Remove("CreatedOn"); ModelState.Remove("ModifiedOn"); ModelState.Remove("ModifiedUsername"); if (ModelState.IsValid) { catManager.Insert(catergory); CacheHelper.RemoveCategoriesFromCache(); return(RedirectToAction("Index")); } return(View(catergory)); }
public ActionResult ByCategory(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Catergory cat = categoryManager.Find(x => x.Id == id.Value); if (cat == null) { return(HttpNotFound()); } return(View("Index", cat.Notes.Where(x => x.IsDraft == false).OrderByDescending(x => x.ModifiedOn).ToList())); // Bu sorguda tasklask durumundakiler görünmezler. Şartlı sorgu. }
public async Task <JsonResult> DeleteCategory([FromBody] Catergory model) { if (!string.IsNullOrEmpty(model.CategoryID)) { Catergory catergory = await _categoryRepository.FindByIdAsync(model.CategoryID); if (catergory != null) { OperationResult result = await _categoryRepository.DeleteRecordAsync(catergory); if (result.Succeeded) { return(Json("Success")); } } } return(Json("Failed")); }
public ActionResult Edit(Catergory catergory) { ModelState.Remove("CreatedOn"); ModelState.Remove("ModifiedOn"); ModelState.Remove("ModifiedUsername"); if (ModelState.IsValid) { // TODO : İncele Catergory cat = catManager.Find(x => x.Id == catergory.Id); cat.Title = catergory.Title; cat.Description = catergory.Description; catManager.Update(catergory); CacheHelper.RemoveCategoriesFromCache(); return(RedirectToAction("Index")); } return(View(catergory)); }
public ActionResult DeleteCatergory(string productId) { try { using (ESamhashoEntities entities = new ESamhashoEntities()) { if (!long.TryParse(productId, out long id)) { return(new ActionResult { Message = "Catergory is invalid." }); } Catergory catergory = entities.Catergories.FirstOrDefault(a => a.Id == id); if (catergory == null) { return new ActionResult { Message = "Catergory does not exist." } } ; catergory.IsDeleted = true; entities.SaveChanges(); return(new ActionResult { Success = true, Message = "Catergory saved successfully." }); } } catch (Exception exception) { Dictionary <string, string> dictionary = new Dictionary <string, string> { { "productId", productId } }; ServiceHelper.LogException(exception, dictionary, ErrorSource.Catergory); return(new ActionResult { Message = "Error, catergory failed to delete, try again." }); } }
public async Task <JsonResult> EditCategory([FromBody] Catergory model) { if (string.IsNullOrEmpty(model.CategoryID.ToString())) { return(Json("Fail")); } Catergory catergory = await _categoryRepository.FindByIdAsync(model.CategoryID.ToString()); if (catergory != null) { catergory.CategoryName = model.CategoryName; } OperationResult result = await _categoryRepository.EditRecordAsync(catergory); if (result.Succeeded) { return(Json("success")); } return(Json("success")); }
public CreateProductResponse CreateProduct(Stream data) { MultipartFormDataParser dataParser = new MultipartFormDataParser(data); string name = dataParser.GetParameterValue("name"); string description = dataParser.GetParameterValue("description"); string catergoryId = dataParser.GetParameterValue("catergory"); string price = dataParser.GetParameterValue("price"); string per = dataParser.GetParameterValue("per"); string shortDescription = dataParser.GetParameterValue("shortDescription"); string manufacturer = dataParser.GetParameterValue("manufacturer"); string code = dataParser.GetParameterValue("code"); string userId = dataParser.GetParameterValue("userId"); string isMain = dataParser.GetParameterValue("IsMain"); string isActive = dataParser.GetParameterValue("isActive"); try { bool.TryParse(isMain, out bool checkMain); bool.TryParse(isActive, out bool checkActive); using (ESamhashoEntities entities = new ESamhashoEntities()) { if (checkActive) { List <Product> products = entities.Products.ToList(); products.ForEach(a => a.IsActive = false); entities.SaveChanges(); } if (checkMain) { List <Product> products = entities.Products.Where(a => a.IsMain).ToList(); if (products.Count > 3) { Product productMain = products.FirstOrDefault(); if (productMain != null) { productMain.IsMain = false; } entities.SaveChanges(); } } Product product = new Product { CatergoryId = int.Parse(catergoryId), Code = code, CreatedDate = DateTime.Now, Description = description, IsDeleted = false, Manufacturer = manufacturer, ModifiedDate = DateTime.Now, Name = name, Per = per, Price = decimal.Parse(price), ShortDescription = shortDescription, UserId = userId, IsMain = checkMain, IsActive = checkActive }; entities.Products.Add(product); entities.SaveChanges(); string path = ServiceHelper.SaveImage(dataParser.Files[0].Data, dataParser.Files[0].FileName); ProductMedia productMedia = new ProductMedia { MediaSource = path, ProductId = product.Id, DateCreate = DateTime.Now, IsDeleted = false, IsMain = true }; entities.ProductMedias.Add(productMedia); entities.SaveChanges(); Catergory catergory = entities.Catergories.FirstOrDefault(a => a.Id == product.CatergoryId); return(new CreateProductResponse { DateCreated = product.CreatedDate.ToLongDateString() + " " + product.CreatedDate.ToLongTimeString(), ProductId = product.Id, MediaSource = path, Catergory = catergory == null? "":catergory.Name }); } } catch (Exception exception) { Dictionary <string, string> dictionary = new Dictionary <string, string> { { "name", name }, { "description", description }, { "catergoryId", catergoryId }, { "price", price }, { "per", per }, { "shortDescription", shortDescription }, { "manufacturer", manufacturer }, { "code", code }, { "userId", userId }, { "mainImage", true.ToString() }, }; ServiceHelper.LogException(exception, dictionary, ErrorSource.Product); return(new CreateProductResponse()); } }
protected override void Seed(DatabaseContex context) { //Adding Fake Admin user EvernoteUser admin = new EvernoteUser() { Username = "******", Name = "Aytaç", Surname = "YANIK", CreatedOn = DateTime.Now, Email = "*****@*****.**", ActivateGuid = Guid.NewGuid(), IsAdmin = true, IsActive = true, Password = "******", ModifiedUsername = "******", ModifiedOn = DateTime.Now.AddMinutes(5), ProfileImaFilename = "user.png" }; //Adding Fake standart user EvernoteUser standartUser = new EvernoteUser() { Username = "******", Name = "AytaçAytaç", Surname = "YANIK", CreatedOn = DateTime.Now.AddHours(1), Email = "*****@*****.**", ActivateGuid = Guid.NewGuid(), IsAdmin = false, IsActive = true, Password = "******", ModifiedUsername = "******", ModifiedOn = DateTime.Now.AddMinutes(65), ProfileImaFilename = "user.png" }; context.EvernoteUsers.Add(admin); context.EvernoteUsers.Add(standartUser); for (int i = 0; i < 8; i++) { EvernoteUser user = new EvernoteUser() { Username = $"user{i}", Name = FakeData.NameData.GetFirstName(), Surname = FakeData.NameData.GetSurname(), CreatedOn = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now), ModifiedOn = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now), Email = FakeData.NetworkData.GetEmail(), ActivateGuid = Guid.NewGuid(), IsAdmin = false, IsActive = true, Password = "******", ModifiedUsername = $"user{i}", ProfileImaFilename = "user.png" }; context.EvernoteUsers.Add(user); } context.SaveChanges(); //UserList for using.. List <EvernoteUser> userList = context.EvernoteUsers.ToList(); //Adding Fake Categories for (int i = 0; i < 10; i++) { Catergory cat = new Catergory() { Title = FakeData.PlaceData.GetStreetName(), Description = FakeData.PlaceData.GetAddress(), CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, ModifiedUsername = "******" }; context.Categories.Add(cat); //Adding Fake Notes for (int k = 0; k < FakeData.NumberData.GetNumber(5, 10); k++) { EvernoteUser owner = userList[FakeData.NumberData.GetNumber(0, userList.Count - 1)]; Note note = new Note() { Title = FakeData.TextData.GetAlphabetical(FakeData.NumberData.GetNumber(5, 25)), Text = FakeData.TextData.GetSentences(FakeData.NumberData.GetNumber(1, 3)), //Catergory = cat, IsDraft = false, LikeCount = FakeData.NumberData.GetNumber(1, 7), Owner = owner, CreatedOn = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now), ModifiedOn = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now), ModifiedUsername = owner.Username }; cat.Notes.Add(note); //Adding Fake Comments for (int j = 0; j < FakeData.NumberData.GetNumber(3, 5); j++) { EvernoteUser comment_owner = userList[FakeData.NumberData.GetNumber(0, userList.Count - 1)]; Comment comment = new Comment() { Text = FakeData.TextData.GetSentence(), CreatedOn = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now), ModifiedOn = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now), ModifiedUsername = comment_owner.Username, //Note = note, Owner = comment_owner }; note.Comments.Add(comment); } //Adding Fake Likes for (int m = 0; m < note.LikeCount; m++) { Liked liked = new Liked() { LikedUser = userList[m] }; note.Likes.Add(liked); } } } context.SaveChanges(); }