예제 #1
0
        public IEnumerable<ItemViewModel> RetrieveItemByProduct(ItemViewModel item)
        {
            int productId = item.ProductId;

            var records = from items in db.Items
                          join prod in db.Products on items.ProductId equals prod.ProductId
                          where item.ProductId == prod.ProductId
                          select items;

            return records;
        }
예제 #2
0
        public ItemViewModel Update(int id, ItemViewModel item)
        {
            var currentRecord = db.Items
               .Where(x => x.ItemId == id)
               .FirstOrDefault();

            if (!(String.IsNullOrWhiteSpace(item.Description)))
            {
                currentRecord.Description = item.Description;
                db.SaveChanges();
                return currentRecord;
            }
            return currentRecord;
        }
        public ActionResult ItemSelection(ItemViewModel item)
        {
            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"))
                {
                    //Runs a query to determine if the user is actually an "Supplier" 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 HttpNotFound();
                    }
                    records = _repository.RetrieveItemByProduct(item);
                    ViewBag.ItemId = new SelectList(records, "ItemId", "Description", item.ItemId);
                    TempData["ModelData"] = new ModelViewModel()
                    {
                        ItemId = item.ItemId
                    };
                    GetSupplierNotification();
                    return RedirectToAction("ModelCreation");
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
예제 #4
0
        private AdminUpdateItemViewModel AssignItemDetailsForUpdate(ItemViewModel record)
        {
            if (record == null || record.ItemId < 1)
                return null;

            var itemToUpdate = new AdminUpdateItemViewModel()
            {
                ItemId = record.ItemId,
                ProductId = record.ProductId,
                ItemDescription = record.Description,
                DtUpdated = DateTime.UtcNow
            };

            if (itemToUpdate == null)
                return null;

            return itemToUpdate;
        }
예제 #5
0
 public ItemViewModel Create(ItemViewModel item)
 {
     return null;
 }
예제 #6
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;
        }
예제 #7
0
        private AdminGetItemViewModel AssignItemDetails(ItemViewModel record)
        {
            if (record == null)
                return null;

            var itemDetails = new AdminGetItemViewModel()
            {
                ItemId = record.ItemId,
                ProductId = record.ProductId,
                ProductDescription = (from p in db.Products
                                      where p.ProductId == record.ProductId
                                      select p.Description).FirstOrDefault(),
                ItemDescription = record.Description,
                Status = record.AdminStatus
            };

            if (itemDetails == null)
                return null;

            return itemDetails;
        }
예제 #8
0
        public ActionResult RevertArchive(ItemViewModel 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 itemId = item.ItemId;
                    if (itemId < 1)
                    {
                        RedirectToAction("RetrieveArchives");
                    }
                    if (item == null)
                    {
                        RedirectToAction("RetrieveArchives");
                    }

                    _repository.RevertArchive(itemId);

                    //   return RedirectToAction("Retrieve");
                    return RedirectToAction("RetrieveArchives", new { message = ManageMessageId.RestoreSuccess });
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
예제 #9
0
        public ActionResult Update(int id, ItemViewModel 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, "Product cannot be null");
                    }

                    var updatedItem = _repository.Update(id, item);
                    if (updatedItem == null)
                    {
                        return HttpNotFound();
                    }

                    return RedirectToAction("Retrieve", new { message = ManageMessageId.UpdateSuccess });
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
예제 #10
0
        // GET: Item/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)
                    //{
                    ItemViewModel itemToUpdate = new ItemViewModel();
                    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());
            }
        }
예제 #11
0
        public ActionResult Create(ItemViewModel 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 newItem = new ItemViewModel();

                    //var newTag = new SpecialCategoryViewModel();
                    if (ModelState.IsValid)
                    {
                        item.AdminStatus = "Active";
                        item.Action = "Catalog";
                        item.Controller = "Home";
                        item.DtCreated = DateTime.UtcNow;
                        item.DtUpdated = DateTime.UtcNow;
                        db.Items.Add(item);
                        db.SaveChanges();

                        //We are adding a Tag matching the description of the Item
                        //newTag.Description = item.Description;
                        //db.SpecialCategories.Add(newTag);
                        //db.SaveChanges();

                        return RedirectToAction("Retrieve", new { message = ManageMessageId.AddSuccess });
                    }
                    ViewBag.ProductId = new SelectList(db.Products.Where(x => x.Status == "Active"), "ProductId", "Description", item.ProductId);

                    return View(newItem);
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
예제 #12
0
        // GET: Item/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 ItemViewModel();
                    ViewBag.ProductId = new SelectList(db.Products.Where(x => x.Status == "Active"), "ProductId", "Description");

                    var records = _repository.Retrieve();
                    ViewData["ItemList"] = records;

                    GetNewSupplierActivation();
                    GetNewModelsActivation();
                    return View(newItem);
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }