Ejemplo n.º 1
0
        public ItemViewModel Create(AdminCreateItemViewModel item)
        {
            if (item == null || item.ProductId < 1)
                return null;

            var newItem = AssignItemCreation(item);

            if (item == null)
                return null;

            return newItem;
        }
Ejemplo n.º 2
0
        // GET: AdminItem/Create
        public ActionResult Create()
        {
            try
            {
                if (User.IsInRole("Admin"))
                {
                    var newItem = new AdminCreateItemViewModel();
                    var products = _repo.AdminRetrieveProducts();
                    if (products == null)
                        return RedirectToAction("Home", "Error404");

                    ViewBag.ProductId = new SelectList(products, "ProductId", "Description");

                    return View(newItem);
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(AdminCreateItemViewModel item)
        {
            try
            {
                if (User.IsInRole("Admin"))
                {
                    if (ModelState.IsValid)
                    {
                        if (item == null)
                            return RedirectToAction("Home", "Error404");

                        var newItem = _repo.Create(item);
                        if (newItem == null)
                            return RedirectToAction("Home", "Error404");

                        return RedirectToAction("AdminItem", "Retrieve");
                    }
                    return RedirectToAction("Home", "Error404");
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
Ejemplo n.º 4
0
        private ItemViewModel AssignItemCreation(AdminCreateItemViewModel item)
        {
            if (item == null || item.ProductId < 1)
                return null;

            item.ItemDescription = helper.ConvertToTitleCase(item.ItemDescription);

            var existingRecord = CheckDuplicates(item.ItemDescription);
            if (existingRecord != null)
                return existingRecord;

            var newItem = new ItemViewModel()
            {
                ProductId = item.ProductId,
                Description = item.ItemDescription,
                AdminStatus = "Active",
                DtCreated = DateTime.UtcNow,
                DtUpdated = DateTime.UtcNow,
            };

            if (newItem == null)
                return null;

            db.Items.Add(newItem);
            db.SaveChanges();

            return newItem;
        }