Exemplo n.º 1
0
        public ViewResult Read(int id)
        {
            MachineVM machineVM = new MachineVM();

            machineVM.machine = _context.Machines.Include(m => m.Department).FirstOrDefault(x => x.Id == id);
            return(View(machineVM));
        }
Exemplo n.º 2
0
        public ActionResult Create()
        {
            MachineVM viewModel = new MachineVM();

            viewModel = populateDropDownList(viewModel);
            return(View(viewModel));
        }
Exemplo n.º 3
0
        private MachineVM populateDropDownList(MachineVM viewModel)
        {
            //viewModel.GenderTypeList = EnumService.GetEnumTypesByParent((int)TypeEnum.GenderType);
            viewModel.MachineGroupList      = EnumService.GetMachineGroupList();
            viewModel.BusinessCenterList    = EnumService.GetBusinessCenterList();
            viewModel.ResponsiblePersonList = EnumService.GetPersonTypeList((int)PersonType.ResponsiblePerson);

            return(viewModel);
        }
Exemplo n.º 4
0
        public ViewResult Create()
        {
            MachineVM machineVM = new MachineVM();

            machineVM.selectDepartments = _context.Departments.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Id.ToString()
            }).ToList();

            return(View(machineVM));
        }
Exemplo n.º 5
0
        public ViewResult Update(int id)
        {
            MachineVM machineVM = new MachineVM();

            machineVM.machine           = _context.Machines.FirstOrDefault(x => x.Id == id);
            machineVM.selectDepartments = _context.Departments.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Id.ToString()
            }).ToList();
            return(View(machineVM));
        }
Exemplo n.º 6
0
        public ActionResult Edit(MachineVM viewModel)
        {
            try
            {
                var UserProfile = (UserProfileSessionData)this.Session["UserProfile"];
                if (UserProfile != null)
                {
                    if (ModelState.IsValid)
                    {
                        tbl_Machine item = new tbl_Machine()
                        {
                            ID                  = viewModel.ID,
                            Code                = viewModel.Code,
                            Name                = viewModel.Name,
                            Description         = viewModel.Description,
                            Quantity            = viewModel.Quantity,
                            MachineGroupID      = viewModel.MachineGroupID,
                            BusinessCenterID    = viewModel.BusinessCenterID,
                            ResponsiblePersonID = viewModel.ResponsiblePersonID,
                            UpdateDate          = DateTime.Now,
                            UpdateUser          = UserProfile.UserId
                        };


                        DataOperations dataOperations = new DataOperations();
                        tbl_Machine    dbItem         = dataOperations.UpdateMachine(item);
                        if (dbItem != null)
                        {
                            TempData["success"] = "Ok";
                            TempData["message"] = "Məlumatlar uğurla dəyişdirildi";
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            TempData["success"] = "notOk";
                            TempData["message"] = "Məlumatlar dəyişdirilərkən xəta baş verdi";
                            return(RedirectToAction("Index"));
                        }
                    }
                }

                throw new ApplicationException("Invalid model");
            }
            catch (ApplicationException ex)
            {
                viewModel = populateDropDownList(viewModel);
                return(View(viewModel));
            }
        }
Exemplo n.º 7
0
        //Method to process json file data into C# objects
        public MachineVM InitializeInput(dynamic data)
        {
            MachineVM model = new MachineVM();

            try
            {
                //Set total outlet count
                model.outlet = Convert.ToInt32(data.machine.outlets.count_n);

                //set total available items
                IList <Ingredient> totalItems = new List <Ingredient>();
                foreach (var item in data.machine.total_items_quantity)
                {
                    totalItems.Add(new Ingredient {
                        name = item.Name, quantity = Convert.ToInt32(item.Value)
                    });
                }
                model.availableItems = totalItems.ToList();

                AvailableIngredient.Ingredients = model.availableItems;

                //set given beverages
                List <Beverage> beverages = new List <Beverage>();
                foreach (var item in data.machine.beverages)
                {
                    Beverage          beverage = new Beverage();
                    List <Ingredient> recipes  = new List <Ingredient>();
                    beverage.name = item.Name;
                    foreach (var i in item.Value)
                    {
                        recipes.Add(new Ingredient {
                            name = i.Name, quantity = Convert.ToInt32(i.Value)
                        });
                    }
                    beverage.ingredients = recipes;
                    beverages.Add(beverage);
                }
                model.beverages = beverages;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }


            return(model);
        }
Exemplo n.º 8
0
        public ActionResult Edit(int id)
        {
            MachineVM      viewModel      = new MachineVM();
            DataOperations dataOperations = new DataOperations();

            tbl_Machine tblItem = dataOperations.GetMachineById(id);

            viewModel.ID                  = id;
            viewModel.Code                = tblItem.Code;
            viewModel.Name                = tblItem.Name;
            viewModel.Description         = tblItem.Description;
            viewModel.Quantity            = tblItem.Quantity;
            viewModel.MachineGroupID      = tblItem.MachineGroupID == null?0:(int)tblItem.MachineGroupID;
            viewModel.BusinessCenterID    = tblItem.BusinessCenterID == null ? 0 : (int)tblItem.BusinessCenterID;
            viewModel.ResponsiblePersonID = tblItem.ResponsiblePersonID == null ? 0 : (int)tblItem.ResponsiblePersonID;
            viewModel = populateDropDownList(viewModel);
            return(View(viewModel));
        }
Exemplo n.º 9
0
        //Helper method to verify if all the ingredients are available for a particular beverage
        private IEnumerable <MissingIngredients> CheckMissingIngredients(MachineVM model)
        {
            List <Ingredient>          itemCount = model.availableItems;
            IList <MissingIngredients> result    = new List <MissingIngredients>();

            try
            {
                foreach (var beverage in model.beverages)
                {
                    MissingIngredients product         = new MissingIngredients();
                    List <string>      prodIngredients = new List <string>();

                    foreach (var item in beverage.ingredients)
                    {
                        if (!itemCount.Any(o => o.name == item.name))
                        {
                            if (string.IsNullOrEmpty(product.beverageName))
                            {
                                product.beverageName = beverage.name;
                                prodIngredients.Add(item.name);
                            }
                            else
                            {
                                prodIngredients.Add(item.name);
                            }
                        }
                    }
                    if (product.beverageName != null)
                    {
                        product.ingredients = prodIngredients;
                        result.Add(product);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(result);
        }
Exemplo n.º 10
0
        public ActionResult Index(int?page, string vl, string prm = null)
        {
            MachineRepository repository = new MachineRepository();

            try
            {
                Search search = new Search();

                search = SetValue(page, vl, prm);

                int pageSize   = 15;
                int pageNumber = (page ?? 1);

                MachineVM viewModel = new MachineVM();
                viewModel.Search = search;

                viewModel.Search.pageSize   = pageSize;
                viewModel.Search.pageNumber = pageNumber;

                viewModel.RMachineList = repository.SW_GetMachines(viewModel.Search);

                viewModel.ListCount = repository.SW_GetMachinesCount(viewModel.Search);
                int[] pc = new int[viewModel.ListCount];

                viewModel.Paging = pc.ToPagedList(pageNumber, pageSize);



                return(Request.IsAjaxRequest()
              ? (ActionResult)PartialView("PartialIndex", viewModel)
              : View(viewModel));
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Error", "Error")));
            }
        }
Exemplo n.º 11
0
        //Main method to process the inputs of current test case and return result accordingly
        public void ProcessBeverage(MachineVM model)
        {
            if (model != null)
            {
                List <Ingredient> itemCount = AvailableIngredient.Ingredients;
                int freeOutlets             = model.outlet;

                //Check if All ingredients are present for the given beverages;
                IEnumerable <MissingIngredients> impossibleBeverages = CheckMissingIngredients(model);

                //Check if it is possible to make each given item through the coffee machine
                //Print result accordingly
                foreach (var beverage in model.beverages)
                {
                    if (impossibleBeverages != null && impossibleBeverages.Any(b => b.beverageName == beverage.name))
                    {
                        MissingIngredients item = impossibleBeverages.Where(b => b.beverageName == beverage.name).First();
                        Console.WriteLine(beverage.name + " cannot be prepared because " + item.ingredients.First() + " is not available");
                    }
                    else
                    {
                        //Check if coffee machine outlets are available
                        if (freeOutlets > 0)
                        {
                            bool canPrepare  = true;
                            bool printResult = false;
                            foreach (var item in beverage.ingredients)
                            {
                                if (itemCount.Any(o => o.name == item.name))
                                {
                                    var currentItem = itemCount.FirstOrDefault(o => o.name == item.name);

                                    if (currentItem.quantity >= item.quantity)
                                    {
                                        currentItem.quantity -= item.quantity;
                                    }
                                    else
                                    {
                                        canPrepare = false;
                                        if (!printResult)
                                        {
                                            Console.WriteLine(beverage.name + " cannot be prepared because " + item.name + " is not sufficient");
                                            printResult = true;
                                        }

                                        _repo.UpdateLowIngredientIndicator(currentItem);
                                    }
                                }
                            }
                            if (canPrepare)
                            {
                                freeOutlets--;
                                Console.WriteLine(beverage.name + " is prepared");
                            }
                        }
                        else
                        {
                            Console.WriteLine(beverage.name + " cannot be prepared as free outlet is not available");
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Invalid input data");
                Console.ReadLine();
                return;
            }
            Console.WriteLine();

            _repo.ShowLowIngredientIndicator();
            Console.WriteLine();
            Console.WriteLine("Press Enter for next test case...\n\n\n");
            Console.ReadLine();
        }