Exemplo n.º 1
0
        public ActionResult AllocationHistory(int page = 1)
        {
            AllocationViewModel viewModel = new AllocationViewModel();

            try
            {
                viewModel.PagingInfo = new PagingInfo
                {
                    TotalRecordsCount = allocationService.GetTotalRecordsCountForAllocationHistory(),
                    RecordsPerPage    = RecordsPerPage,
                    CurentPageNo      = page
                };

                if (viewModel.PagingInfo.TotalRecordsCount > 0)
                {
                    viewModel.Allocations = GetAllocationsHistory(page);
                }
                else
                {
                    DisplayWarningMessage("There are no Project Allocations History to display");
                }
            }
            catch (Exception exp)
            {
                DisplayLoadErrorMessage(exp);
            }

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public CardAllocation(AllocationViewModel vm)
        {
            InitializeComponent();
            _vm = vm;

            BindingContext = _vm;
        }
Exemplo n.º 3
0
        // GET: Project
        public ActionResult List(string filterType, string filterValue, int page = 1)
        {
            AllocationViewModel viewModel = new AllocationViewModel()
            {
                FilterType  = filterType,
                FilterValue = filterValue
            };

            try
            {
                InitializeListPage(viewModel);
                int.TryParse(filterValue, out int filterValueID);
                viewModel.PagingInfo = new PagingInfo
                {
                    TotalRecordsCount = allocationService.TotalRecordsCount(filterType, filterValueID),
                    RecordsPerPage    = RecordsPerPage,
                    CurentPageNo      = page
                };

                if (viewModel.PagingInfo.TotalRecordsCount > 0)
                {
                    viewModel.Allocations = GetAllocations(filterType, filterValueID, page);
                }
                else
                {
                    DisplayWarningMessage("There are no Project Allocations to display");
                }
            }
            catch (Exception exp)
            {
                DisplayLoadErrorMessage(exp);
            }

            return(View(viewModel));
        }
        /// <summary>
        /// This function will check if there is enough allocated money. If there is, it will return
        /// with all the investers fully funded. If not, we will calculate the proration. After the
        /// initial calculation each result is checked to make sure that the investor isn't receiving
        /// more than requested.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List <InvestorInfo> Prorate(AllocationViewModel model)
        {
            // If there is enough allocated money for all investers then return.
            if (model.InvestorInfos.Sum(x => x.RequestAmount) <= model.TotalAvailableAllocation)
            {
                return(model.InvestorInfos.Select(x => new InvestorInfo
                {
                    ProratedAmount = x.RequestAmount,
                    Name = x.Name
                }).ToList());
            }

            List <InvestorInfo> resultList = new List <InvestorInfo>();
            bool isDone = false;

            while (!isDone)
            {
                // Calculate the average investment sum then set the prorated amount.
                decimal?averageInvestmentSum = model.InvestorInfos.Sum(x => x.AveragAmount);

                foreach (var investor in model.InvestorInfos)
                {
                    investor.ProratedAmount = (model.TotalAvailableAllocation * (investor.AveragAmount) / (averageInvestmentSum));
                }

                isDone = calculateProration(model, resultList);
            }

            return(resultList.Concat(model.InvestorInfos).ToList());
        }
Exemplo n.º 5
0
        public ActionResult ReallocatePrisoner(int?id)
        {
            if (id != null)
            {
                Prisoners  prisoner  = _db.Prisoners.FirstOrDefault(x => x.Prisoner_Id == id.Value);
                Judgements judgement = _db.Judgements.FirstOrDefault(x => x.FK_Judgements_Prisoners_Id == id);

                var model = new AllocationViewModel()
                {
                    Prisoner_Id        = id.Value,
                    CategoryOfCrime_Id = judgement.FK_Judgements_CategoriesOfCrimes_Id,
                    Sex = prisoner.PrisonerSurname
                };



                model.Cells = from c in _db.Cells
                              join branch in _db.Branches
                              on c.FK_Cells_Branch equals branch.Branch_id
                              join branchSex in _db.BranchesSex
                              on branch.Branch_id equals branchSex.FK_BranchesSex_Branches_Id
                              where branchSex.FK_BranchesSex_CategoriesOfCrimes_Id == judgement.FK_Judgements_CategoriesOfCrimes_Id && c.IsEmpty &&
                              branchSex.Sex == prisoner.Sex && c.Cell_Id != ReleasePrisonerClass.Placeholder
                              select c;

                if (model.Cells.Any() == false)
                {
                    TempData["alertMessage"] = "Brak dostępnych cel";
                    return(RedirectToAction("GetPrisoners", "Prisoners"));
                }
                ViewBag.CelList = new SelectList(model.Cells, "Cell_Id", "Cell_Id");
                return(View(model));
            }
            return(HttpNotFound());
        }
Exemplo n.º 6
0
 public ActionResult AllocatePrisoner(AllocationViewModel model)
 {
     if (ModelState.IsValid)
     {
         var cell = _db.Cells.FirstOrDefault(x => x.Cell_Id == model.Cell_Id);
         if (cell == null)
         {
             return(HttpNotFound());
         }
         var count = _db.Allocation.Count(x => x.FK_Allocation_Cells_Id == cell.Cell_Id);
         if (cell.IsEmpty && count < cell.Size)
         {
             var allocation = new Allocation
             {
                 FK_Allocation_Cells_Id     = cell.Cell_Id,
                 FK_Allocation_Prisoners_Id = model.Prisoner_Id
             };
             if (count + 1 == cell.Size)
             {
                 cell.IsEmpty          = false;
                 _db.Entry(cell).State = EntityState.Modified;
             }
             _db.Allocation.Add(allocation);
             _db.SaveChanges();
             return(RedirectToAction("GetPrisoners", "Prisoners"));
         }
     }
     return(View(model));
 }
Exemplo n.º 7
0
        public ActionResult AllocatePrisoner(int?id)
        {
            var model = new AllocationViewModel();

            if (id != null)
            {
                model.Prisoner_Id = id.Value;

                Prisoners prisoner = _db.Prisoners.FirstOrDefault(x => x.Prisoner_Id == id);

                model.Sex = prisoner.Sex;

                Judgements judgement = _db.Judgements.FirstOrDefault(x => x.FK_Judgements_Prisoners_Id == id);
                model.CategoryOfCrime_Id = judgement.FK_Judgements_CategoriesOfCrimes_Id;

                model.Cells = from c in _db.Cells
                              join o in _db.Branches
                              on c.FK_Cells_Branch equals o.Branch_id
                              join x in _db.BranchesSex
                              on o.Branch_id equals x.FK_BranchesSex_Branches_Id
                              where x.FK_BranchesSex_CategoriesOfCrimes_Id == judgement.FK_Judgements_CategoriesOfCrimes_Id && c.IsEmpty &&
                              x.Sex == prisoner.Sex && c.Cell_Id != ReleasePrisonerClass.Placeholder
                              select c;

                ViewBag.CelList = new SelectList(model.Cells, "Cell_Id", "Cell_Id");
                return(View(model));
            }
            return(HttpNotFound());
        }
        private void InitializeListPage(AllocationViewModel viewModel)
        {
            viewModel.FilterTypeDropDownItems = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text  = "Employee",
                    Value = "emp"
                },
                new SelectListItem
                {
                    Text  = "Project",
                    Value = "prj"
                },
                new SelectListItem
                {
                    Text  = "Project Manager",
                    Value = "pm"
                },
            };

            if (string.IsNullOrEmpty(viewModel.FilterType) == false && Session["FilterValueListItemsAllocation"] != null)
            {
                viewModel.FilterValueDropDownItems = (List <SelectListItem>)Session["FilterValueListItemsAllocation"];
            }
        }
Exemplo n.º 9
0
        public ActionResult ReallocatePrisoner(AllocationViewModel model)
        {
            var id = System.Web.HttpContext.Current.User.Identity.GetUserId();


            var cell = _db.Cells.FirstOrDefault(x => x.Cell_Id == model.Cell_Id);

            if (cell == null)
            {
                return(HttpNotFound());
            }
            var count = _db.Allocation.Count(x => x.FK_Allocation_Cells_Id == cell.Cell_Id);

            if (cell.IsEmpty && count < cell.Size)
            {
                var allocation = _db.Allocation.FirstOrDefault(s => s.FK_Allocation_Prisoners_Id == model.Prisoner_Id);

                if (allocation != null)
                {
                    allocation.FK_Allocation_Cells_Id = cell.Cell_Id;
                    _db.Entry(allocation).State       = EntityState.Modified;
                }
                var history = new ChangesHistory()
                {
                    Worker_Id = id,
                    Date      = DateTime.Now.Date
                };

                var allocationHistory = new AllocationChangesHistory()
                {
                    Cell_Id = cell.Cell_Id,
                    FK_AllocationChangesHistory_ChangesHistory_Id = history.Record_Id,
                    FK_AllocationChangesHistory_Allocation_Id     = allocation.FK_Allocation_Prisoners_Id
                };
                if (count + 1 == cell.Size)
                {
                    cell.IsEmpty          = false;
                    _db.Entry(cell).State = EntityState.Modified;
                }
                if (count - 1 < cell.Size)
                {
                    cell.IsEmpty          = true;
                    _db.Entry(cell).State = EntityState.Modified;
                }


                _db.ChangesHistory.Add(history);
                _db.AllocationChangesHistory.Add(allocationHistory);
                _db.SaveChanges();
                return(RedirectToAction("GetPrisoners", "Prisoners"));
            }
            return(View(model));
        }
Exemplo n.º 10
0
        public IActionResult Index()
        {
            var model = new AllocationViewModel();

            model.InvestorInfos.Add(new InvestorInfo());
            model.InvestorInfos.Add(new InvestorInfo());
            model.InvestorInfos.Add(new InvestorInfo());

            ViewData["results"] = new List <InvestorInfo>();

            return(View(model));
        }
Exemplo n.º 11
0
 public AllocationViewPage(AllocationViewModel vm)
 {
     InitializeComponent();
     BindingContext = _vm = vm;
     MapImage.GestureRecognizers.Add(new TapGestureRecognizer {
         Command = new Command(() =>
         {
             Device.OpenUri(new Uri(_vm.MapClickUrl));
         }),
         NumberOfTapsRequired = 1
     });
 }
Exemplo n.º 12
0
        /// <summary>
        /// Helper function to determine if the prorated amout is greater than the requested amount.
        /// If the prorated amount is greater, we set that value to the requested amount and move it
        /// to a temporary list. Then begin the caluclation process over again with the remaining list.
        /// </summary>
        /// <param name="model">Object used in parent function that is used to check prorated amount.</param>
        /// <param name="infoList">Temporary list to hold InvestorInfo</param>
        /// <returns></returns>
        private bool calculateProration(AllocationViewModel model, List <InvestorInfo> infoList)
        {
            foreach (InvestorInfo investorInfo in model.InvestorInfos)
            {
                if (investorInfo.ProratedAmount > investorInfo.RequestAmount)
                {
                    investorInfo.ProratedAmount    = investorInfo.RequestAmount;
                    model.TotalAvailableAllocation = (decimal)(model.TotalAvailableAllocation - investorInfo.RequestAmount);
                    infoList.Add(investorInfo);
                    model.InvestorInfos.Remove(investorInfo);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 13
0
        public IActionResult Index(AllocationViewModel model)
        {
            if (!validateFormData(model))
            {
                ViewData["results"] = new List <InvestorInfo>();
                return(View(model));
            }

            // Copies the 'model' into a new alocation model. This is so the view can display the original info since the
            // proration service modifies the 'model' data.
            AllocationViewModel dataModel = new AllocationViewModel()
            {
                InvestorInfos            = model.InvestorInfos.Where(x => x.AveragAmount != null && x.RequestAmount != null).ToList(),
                TotalAvailableAllocation = model.TotalAvailableAllocation
            };

            ViewData["results"] = _prorationService.Prorate(dataModel);

            return(View(model));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Checks the form data to make sure the user inputs enough data to do the calculation.
        ///
        /// This will make sure there is a Total Available Allocation number set as well as the RequestAmount
        /// and Average Amount.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private bool validateFormData(AllocationViewModel model)
        {
            if (model.TotalAvailableAllocation == 0)
            {
                ModelState.AddModelError("error", "Total Available Allocation Required. Must be decimal value");
                return(false);
            }

            foreach (var investorInfo in model.InvestorInfos)
            {
                if ((investorInfo.RequestAmount == null && investorInfo.AveragAmount != null) || (investorInfo.RequestAmount != null && investorInfo.AveragAmount == null))
                {
                    ModelState.AddModelError("error", "One of the input values is either missing or is not a decimal value");
                    return(false);
                }
            }
            if (ModelState.ContainsKey("error"))
            {
                ModelState["error"].Errors.Clear();
            }
            return(true);
        }
        public ActionResult AllocationHistory(string filterType = "Please Select", string filterValue = "0", string sortBy = "EmployeeName", string sortType = "asc", int page = 1)
        {
            AllocationViewModel viewModel = new AllocationViewModel()
            {
                FilterType  = filterType,
                FilterValue = filterValue,
                SortBy      = sortBy,
                SortType    = sortType
            };

            int.TryParse(filterValue, out int filterValueID);
            try
            {
                viewModel.PagingInfo = new PagingInfo
                {
                    TotalRecordsCount = allocationService.GetTotalRecordsCountForAllocationHistory(filterType, filterValueID),
                    RecordsPerPage    = RecordsPerPage,
                    CurentPageNo      = page
                };

                InitializeListPage(viewModel);
                if (viewModel.PagingInfo.TotalRecordsCount > 0)
                {
                    viewModel.Allocations = GetAllocationsHistory(filterType, filterValueID, sortBy, sortType, page);
                }
                else
                {
                    DisplayWarningMessage("No records to display");
                }
            }
            catch (Exception exp)
            {
                DisplayLoadErrorMessage(exp);
            }

            return(View(viewModel));
        }
Exemplo n.º 16
0
 public IActionResult AddInvestorInfoItem([Bind("InvestorInfos")] AllocationViewModel allocationViewModel)
 {
     allocationViewModel.InvestorInfos.Add(new InvestorInfo());
     return(PartialView("InvestorInfo", allocationViewModel));
 }