public BrandViewModel Create(BrandViewModel item) { var newRecord = new BrandViewModel { Name = item.Name, Status = "Active" }; db.Brands.Add(newRecord); db.SaveChanges(); return newRecord; }
public BrandViewModel Update(int id, BrandViewModel item) { var currentrecord = db.Brands .Where(x => x.BrandId == id) .FirstOrDefault(); if (!(String.IsNullOrWhiteSpace(item.Name))) { currentrecord.Name = item.Name; } db.SaveChanges(); return currentrecord; }
public ActionResult RevertArchive(BrandViewModel item) { try { string userId = User.Identity.GetUserId(); if (userId == null) { return RedirectToAction("Login", "Account"); } //Check if the "Admin" role exists if not it returns a null value var role = db.Roles.SingleOrDefault(m => m.Name == "Admin"); if (User.IsInRole("Admin")) { //Runs a query to determine if the user is actually an "Admin" if not it returns a null value //var userInRole = db.Users.Where(m => m.Roles.Any(r => r.UserId == userId)).FirstOrDefault(); //if (userInRole != null) //{ var brandId = item.BrandId; if (brandId < 1) { RedirectToAction("RetrieveArchives", new { message = ManageMessageId.Error }); } if (item == null) { RedirectToAction("RetrieveArchives"); } _repository.RevertArchive(brandId); // return RedirectToAction("Retrieve"); return RedirectToAction("RetrieveArchives", new { message = ManageMessageId.RestoreSuccess }); } return RedirectToAction("Login", "Account"); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()); } }
// GET: Brand/Edit/5 public ActionResult Update(int id) { try { string userId = User.Identity.GetUserId(); if (userId == null) { return RedirectToAction("Login", "Account"); } //Check if the "Admin" role exists if not it returns a null value var role = db.Roles.SingleOrDefault(m => m.Name == "Admin"); if (User.IsInRole("Admin")) { //Runs a query to determine if the user is actually an "Admin" if not it returns a null value //var userInRole = db.Users.Where(m => m.Roles.Any(r => r.UserId == userId)).FirstOrDefault(); //if (userInRole != null) //{ BrandViewModel itemToUpdate = new BrandViewModel(); if (id < 1) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid Identifier"); } itemToUpdate = _repository.Get(id); if (itemToUpdate == null) { return HttpNotFound(); } GetNewSupplierActivation(); GetNewModelsActivation(); return View(itemToUpdate); } return RedirectToAction("Login", "Account"); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()); } }
public ActionResult Create(BrandViewModel item) { try { string userId = User.Identity.GetUserId(); if (userId == null) { return RedirectToAction("Login", "Account"); } //Check if the "Admin" role exists if not it returns a null value var role = db.Roles.SingleOrDefault(m => m.Name == "Admin"); if (User.IsInRole("Admin")) { //Runs a query to determine if the user is actually an "Admin" if not it returns a null value //var userInRole = db.Users.Where(m => m.Roles.Any(r => r.UserId == userId)).FirstOrDefault(); //if (userInRole != null) //{ if (item == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Item cannot be null!"); } var newItem = _repository.Create(item); return RedirectToAction("Retrieve", new { message = ManageMessageId.AddSuccess }); } return RedirectToAction("Login", "Account"); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()); } }
// GET: Brand/Create public ActionResult Create() { try { string userId = User.Identity.GetUserId(); if (userId == null) { return RedirectToAction("Login", "Account"); } //Check if the "Admin" role exists if not it returns a null value var role = db.Roles.SingleOrDefault(m => m.Name == "Admin"); if (User.IsInRole("Admin")) { //Runs a query to determine if the user is actually an "Admin" if not it returns a null value //var userInRole = db.Users.Where(m => m.Roles.Any(r => r.UserId == userId)).FirstOrDefault(); //if (userInRole != null) //{ var newItem = new BrandViewModel(); var records = _repository.Retrieve(); ViewData["BrandList"] = records; GetNewSupplierActivation(); GetNewModelsActivation(); return View(newItem); } return RedirectToAction("Login", "Account"); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()); } }
public ActionResult ModelCreation(SpecProductViewModel item, HttpPostedFileBase modelPhoto) { try { string userId = User.Identity.GetUserId(); if (userId == null) { return RedirectToAction("Login", "Account"); } //Check if the "Supplier" role exists if not it returns a null value var role = db.Roles.SingleOrDefault(m => m.Name == "Supplier"); if (User.IsInRole("Supplier")) { var photo = UploadPhoto(modelPhoto, item); if (photo != null) { SpecProductViewModel specProd = Session["SpecProd"] as SpecProductViewModel; int brandId = 0; //This object will allow us to use the convert to ConvertToTitleCase method var helper = new Helper(); //Convert to Title Case item.BrandName = helper.ConvertToTitleCase(item.BrandName); //Check if brand name exists var brand = (from b in db.Brands where b.Name == item.BrandName select b).FirstOrDefault(); //If the brand does not exist create a new one if (brand == null) { var newBrand = new BrandViewModel() { Name = item.BrandName }; db.Brands.Add(newBrand); db.SaveChanges(); brandId = newBrand.BrandId; } //if the brand does exist assign the existing brandId to the brandId of the new model if (brand != null) { brandId = brand.BrandId; } //Create a new instance of ModelViewModel and assign it to the model variable var model = new ModelViewModel(); model.Price = item.Price; model.Status = specProd.Status; model.UserId = userId; model.SupplierId = specProd.SupplierId; model.ItemId = specProd.ItemId; model.BrandId = brandId; model.ModelNumber = item.ModelNumber; model.DtCreated = DateTime.UtcNow; model.NumberDaysToAdvert = item.NumberDaysToAdvert; model.DeliveryInDays = item.DeliveryInDays; //Add a new model to the table model and save changes into the database db.Models.Add(model); db.SaveChanges(); var modelCommission = new ModelCommissionViewModel() { ModelId = model.ModelId }; string commissionName = "Tier1"; if (model.NumberDaysToAdvert >= 1 && model.NumberDaysToAdvert < 6) commissionName = "Tier1"; if (model.NumberDaysToAdvert >= 6 && model.NumberDaysToAdvert < 20) commissionName = "Tier2"; if (model.NumberDaysToAdvert >= 20) commissionName = "Tier3"; int commissionId = (from c in db.Commissions where c.Name == commissionName select c.CommissionId).FirstOrDefault(); modelCommission.CommissionId = commissionId; db.ModelCommissions.Add(modelCommission); db.SaveChanges(); var photoModel = new PhotoModelViewModel() { PhotoId = photo.PhotoId, ModelId = model.ModelId }; db.PhotoModels.Add(photoModel); db.SaveChanges(); Session["ModelSpecData"] = model; GetSupplierNotification(); return RedirectToAction("ModelSpecCreation"); //return RedirectToAction("ModelSpecCreation");on("ModelSpecCreation"); } } return RedirectToAction("Login", "Account"); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()); } }