Example #1
0
        public IActionResult Edit([FromRoute] int id, [Bind("ItemName,StoreName,SellerName,TopicName,ItemName,ItemDescription,ItemPrice")] ItemViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Domain.Model.Item item = Repo.GetItemById(id);
                    item.Name        = viewModel.ItemName;
                    item.Description = viewModel.ItemDescription;
                    item.Price       = viewModel.ItemPrice;
                    item.StoreId     = RepoStore.GetStoresByName(viewModel.StoreName).First(p => p.Name.ToLower() == viewModel.StoreName.ToLower()).Id;
                    item.OrderId     = viewModel.OrderId;
                    item.SellerId    = RepoSell.GetSellersByName(viewModel.SellerName).First(p => p.Name.ToLower() == viewModel.SellerName.ToLower()).Id;
                    item.TopicId     = RepoTopi.GetTopicByName(viewModel.TopicName).First(p => p.Topic.ToLower() == viewModel.TopicName.ToLower()).Id;
                    Repo.UpdateItem(item);
                    Repo.Save();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(viewModel));
            }
            catch (Exception)
            {
                return(View(viewModel));
            }
        }
Example #2
0
        // GET: Items/Create
        public IActionResult Create()
        {
            List <string> mySellers = new List <string> ();

            foreach (var val in RepoSell.GetSellersByName().ToList())
            {
                mySellers.Add(val.Name);
            }
            ViewData["Seller"] = new SelectList(mySellers);
            List <string> myTopics = new List <string> ();

            foreach (var val in RepoTopi.GetTopicByName().ToList())
            {
                myTopics.Add(val.Topic);
            }
            ViewData["Topic"] = new SelectList(myTopics);
            List <string> myStores = new List <string> ();

            foreach (var val in RepoStore.GetStoresByName().ToList())
            {
                myStores.Add(val.Name);
            }
            ViewData["Store"] = new SelectList(myStores);
            return(View());
        }
Example #3
0
        public IActionResult Create([Bind("ItemName,StoreName,SellerName,TopicName,ItemName,ItemDescription,ItemPrice")] ItemViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var myStore  = RepoStore.GetStoresByName().First(p => p.Name.ToLower() == viewModel.StoreName.ToLower()).Id;
                    var mySeller = RepoSell.GetSellersByName().First(p => p.Name.ToLower() == viewModel.SellerName.ToLower()).Id;
                    var myTopic  = RepoTopi.GetTopicByName().First(p => p.Topic.ToLower() == viewModel.TopicName.ToLower()).Id;
                    var item     = new Domain.Model.Item
                    {
                        Id          = 0,
                        Name        = viewModel.ItemName,
                        Description = viewModel.ItemDescription,
                        Price       = viewModel.ItemPrice,
                        StoreId     = myStore,
                        OrderId     = viewModel.OrderId,
                        SellerId    = mySeller,
                        TopicId     = myTopic
                    };
                    Repo.AddItem(item);
                    Repo.Save();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(viewModel));
            }
            catch
            {
                return(View(viewModel));
            }
        }
        // GET: Items
        public ActionResult Index([FromQuery] string search = "")
        {
            List <Domain.Model.Store> stores     = RepoStore.GetStoresByName();
            List <StoreViewModel>     realStores = new List <StoreViewModel>();

            foreach (var val in stores)
            {
                int stockcount = 0;
                foreach (var val2 in val.Items)
                {
                    if (val2.OrderId == null || val2.OrderId == 0)
                    {
                        stockcount++;
                    }
                }
                realStores.Add(new StoreViewModel
                {
                    StoreId      = val.Id,
                    LocationName = val.Name,
                    ItemCount    = stockcount
                });
            }
            if (search != null)
            {
                return(View(realStores.FindAll(p => p.LocationName.ToLower().Contains(search.ToLower()))));
            }
            return(View(realStores));
        }
        public IActionResult Create([Bind("LocationName")] StoreViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var store = new Domain.Model.Store
                    {
                        Id    = viewModel.StoreId,
                        Name  = viewModel.LocationName,
                        Items = RepoItem.GetItemsByStoreName(viewModel.LocationName)
                                .FindAll(p => p.StoreId == (RepoStore.GetStoresByName(viewModel.LocationName)
                                                            .First(p => p.Name == viewModel.LocationName).Id)),
                    };

                    RepoStore.AddStore(store);
                    RepoStore.Save();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(viewModel));
            }
            catch
            {
                return(View(viewModel));
            }
        }
        public IActionResult Create([Bind("FirstName,LastName,Username,Password,Employee,StoreName")] PersonViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var person = new Domain.Model.Person
                    {
                        Id          = viewModel.PersonId,
                        FirstName   = viewModel.FirstName,
                        LastName    = viewModel.LastName,
                        Username    = viewModel.Username,
                        Password    = viewModel.Password,
                        EmployeeTag = false,
                        StoreId     = RepoStore.GetStoresByName(viewModel.StoreName).First(p => p.Name.ToLower() == viewModel.StoreName.ToLower()).Id,
                    };
                    List <string> myStores = new List <string> ();
                    foreach (var val in RepoStore.GetStoresByName().ToList())
                    {
                        myStores.Add(val.Name);
                    }
                    ViewData["StoreName"] = new SelectList(myStores);

                    RepoPers.AddPerson(person);
                    RepoPers.Save();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(viewModel));
            }
            catch
            {
                return(View(viewModel));
            }
        }
        public IActionResult Edit([FromRoute] int id, [Bind("FirstName,LastName,Username,Password,Employee,StoreName")] PersonViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Domain.Model.Person person = RepoPers.GetPersonById(id);
                    person.FirstName   = viewModel.FirstName;
                    person.LastName    = viewModel.LastName;
                    person.Username    = viewModel.Username;
                    person.Password    = viewModel.Password;
                    person.EmployeeTag = viewModel.Employee;
                    person.StoreId     = RepoStore.GetStoresByName(viewModel.StoreName).First(p => p.Name.ToLower() == viewModel.StoreName.ToLower()).Id;
                    RepoPers.UpdatePerson(person);
                    RepoPers.Save();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(viewModel));
            }
            catch (Exception)
            {
                return(View(viewModel));
            }
        }
        // GET: Items/Edit/5
        public IActionResult Edit(int id)
        {
            // we pass the current values into the Edit view
            // so that the input fields can be pre-populated instead of blank
            // (important for good UX)
            Domain.Model.Person person = RepoPers.GetPersonById(id);
            var viewModel = new PersonViewModel
            {
                PersonId  = person.Id,
                FirstName = person.FirstName,
                LastName  = person.LastName,
                Username  = person.Username,
                Password  = person.Password,
                Employee  = person.EmployeeTag,
                StoreName = RepoStore.GetStoreById(person.StoreId).Name,
            };
            List <string> myStores = new List <string> ();

            foreach (var val in RepoStore.GetStoresByName().ToList())
            {
                myStores.Add(val.Name);
            }
            ViewData["StoreName"] = new SelectList(myStores);
            return(View(viewModel));
        }
        // GET: Items/Create
        public IActionResult Create()
        {
            List <string> myStores = new List <string> ();

            foreach (var val in RepoStore.GetStoresByName().ToList())
            {
                myStores.Add(val.Name);
            }
            ViewData["StoreName"] = new SelectList(myStores);
            return(View());
        }
Example #10
0
        // GET: Items/Edit/5
        public IActionResult Edit(int id)
        {
            // we pass the current values into the Edit view
            // so that the input fields can be pre-populated instead of blank
            // (important for good UX)
            Domain.Model.Item item = Repo.GetItemById(id);
            var viewModel          = new ItemViewModel
            {
                ItemId          = item.Id,
                ItemName        = item.Name,
                ItemDescription = item.Description,
                ItemPrice       = item.Price,
                StoreName       = RepoStore.GetStoreById(item.StoreId).Name,
                OrderId         = item.OrderId,
                SellerName      = RepoSell.GetSellerById(item.SellerId).Name,
                TopicName       = RepoTopi.GetTopicById(item.TopicId).Topic
            };
            List <string> mySellers = new List <string> ();

            foreach (var val in RepoSell.GetSellersByName().ToList())
            {
                mySellers.Add(val.Name);
            }
            ViewData["Seller"] = new SelectList(mySellers);
            List <string> myTopics = new List <string> ();

            foreach (var val in RepoTopi.GetTopicByName().ToList())
            {
                myTopics.Add(val.Topic);
            }
            ViewData["Topic"] = new SelectList(myTopics);
            List <string> myStores = new List <string> ();

            foreach (var val in RepoStore.GetStoresByName().ToList())
            {
                myStores.Add(val.Name);
            }
            ViewData["Store"] = new SelectList(myStores);
            return(View(viewModel));
        }
        public IActionResult Edit([FromRoute] int id, [Bind("LocationName")] StoreViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Domain.Model.Store store = RepoStore.GetStoreById(id);
                    store.Name  = viewModel.LocationName;
                    store.Items = RepoItem.GetItemsByStoreName(viewModel.LocationName)
                                  .FindAll(p => p.StoreId == (RepoStore.GetStoresByName(viewModel.LocationName)
                                                              .First(p => p.Name == viewModel.LocationName).Id));
                    RepoStore.UpdateStore(store);
                    RepoStore.Save();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(viewModel));
            }
            catch (Exception)
            {
                return(View(viewModel));
            }
        }