public async Task <IActionResult> Create([Bind("Weight,Price,Cart,Size,Description,Amount,Discount,Id,Diamonds,ImagePath,Name,CategoryId,SetId")] Jewelry jewelry) { if (Account.isAdmin(User)) { if (ModelState.IsValid) { _context.Add(jewelry); await _context.SaveChangesAsync(); string postToFacebook = ("התכשיט " + jewelry.Name + " נוסף לחנות. יש " + jewelry.Amount + " פריטים. היכנסו לאתר בשביל לקנות"); FacebookPost post = new FacebookPost(); post.PublishToFacebookNoPhoto(postToFacebook); return(RedirectToAction("Index")); } ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", jewelry.CategoryId); ViewData["SetId"] = new SelectList(_context.JewelrySet, "Id", "Name", jewelry.SetId); return(View(jewelry)); } else { return(new RedirectToActionResult("NotAuthorized", "Home", null)); } }
public async Task <IActionResult> Create([Bind("Name,Address,CoordinateLat,CoordinateLng,ManagerId,Id")] Branch branch) { if (Account.isAdmin(User)) { if (ModelState.IsValid) { _context.Add(branch); await _context.SaveChangesAsync(); string postToFacebook = ("החנות " + branch.Name + " התווספה. מוזמנים לבקר בכתובת " + branch.Address + ". בואו בהמוניכם !!!"); FacebookPost post = new FacebookPost(); post.PublishToFacebookNoPhoto(postToFacebook); return(RedirectToAction("Index")); } ViewData["ManagerId"] = new SelectList(_context.Users, "Id", "Id", branch.ManagerId); return(View(branch)); } else { return(new RedirectToActionResult("NotAuthorized", "Home", null)); } }
public async Task <IActionResult> Edit(int id, [Bind("Weight,Price,Cart,Size,Description,Amount,Discount,Id,Diamonds,ImagePath,Name,CategoryId,SetId")] Jewelry jewelry) { if (id != jewelry.Id) { return(NotFound()); } if (Account.isAdmin(User)) { if (ModelState.IsValid) { try { ColmanInternetiotContext newContext = new ColmanInternetiotContext(); int?currAmount = newContext.Jewelry.First(x => x.Id == jewelry.Id).Amount; _context.Update(jewelry); await _context.SaveChangesAsync(); if (currAmount != null) { string postToFacebook = ("לתכשיט " + jewelry.Name + " נוספו " + (jewelry.Amount - int.Parse(currAmount.ToString())) + " פריטים חדשים. היכנסו לאתר בשביל לקנות"); FacebookPost post = new FacebookPost(); post.PublishToFacebookNoPhoto(postToFacebook); } } catch (DbUpdateConcurrencyException) { if (!JewelryExists(jewelry.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", jewelry.CategoryId); ViewData["SetId"] = new SelectList(_context.JewelrySet, "Id", "Name", jewelry.SetId); return(View(jewelry)); } else { return(new RedirectToActionResult("NotAuthorized", "Home", null)); } }