Exemple #1
0
        public SpecialCategoryViewModel Create(SpecialCategoryViewModel item)
        {
            if (String.IsNullOrEmpty(item.Description))
                return null;

            SpecialCategoryViewModel existingRecord = null;

            string descriptionTitleCase = helper.ConvertToTitleCase(item.Description);
            existingRecord = CheckForDuplicates(descriptionTitleCase);
            if (existingRecord == null)
            {
                var newRecord = new SpecialCategoryViewModel
                {
                    Description = descriptionTitleCase,
                    Position = item.Position
                };

                db.SpecialCategories.Add(newRecord);
                db.SaveChanges();

                return newRecord;
            }

            return existingRecord;
        }
Exemple #2
0
        public SpecialCategoryViewModel Update(int id, SpecialCategoryViewModel item)
        {
            var currentrecord = db.SpecialCategories
                .Where(x => x.SpecialCatId == id)
                .FirstOrDefault();

            if (!(String.IsNullOrWhiteSpace(item.Description)))
            {
                currentrecord.Description = item.Description;
            }
            db.SaveChanges();

            return currentrecord;
        }
        // GET: SupplierSpecialCategory/Create
        public ActionResult Create()
        {
            try
            {
                if (User.IsInRole("Supplier"))
                {
                    var newItem = new SpecialCategoryViewModel();

                    var records = _repository.Retrieve();
                    ViewData["TagList"] = records;
                    return View(newItem);
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
        public ActionResult Create(SpecialCategoryViewModel item)
        {
            try
            {
                if (User.IsInRole("Supplier"))
                {
                    if (item == null)
                    {
                        return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Item cannot be null!");
                    }

                    var newItem = _repository.Create(item);

                    return RedirectToAction("Retrieve");
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
        public ActionResult Update(int id, SpecialCategoryViewModel item)
        {
            try
            {
                if (User.IsInRole("Admin"))
                {
                    if (item == null)
                    {
                        return RedirectToAction("Retrieve", new { message = ManageMessageId.Error });
                    }

                    var updatedItem = _repository.Update(id, item);
                    if (updatedItem == null)
                    {
                        return RedirectToAction("Retrieve", new { message = ManageMessageId.Error });
                    }

                    return RedirectToAction("Retrieve", new { message = ManageMessageId.UpdateSuccess });
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
        // GET: Tag/Edit/5
        public ActionResult Update(int id)
        {
            try
            {
                if (User.IsInRole("Admin"))
                {
                    SpecialCategoryViewModel itemToUpdate = new SpecialCategoryViewModel();
                    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());
            }
        }