Beispiel #1
0
        public async Task <IActionResult> AddNewCollection(CollectionModel collectionModel)
        {
            List <CollectionModel> collection = await _collectionRepository.GetAllCollection(collectionModel.ProjectsID);

            var contractValue = _context.PreSalesProjects.Single(b => b.ID == collectionModel.ProjectsID).value;

            ViewBag.isExeed = false;

            double curentCollectionBudget = 0;

            if (collection != null)
            {
                foreach (CollectionModel item in collection)
                {
                    curentCollectionBudget = curentCollectionBudget + item.value;
                }
                if (curentCollectionBudget + collectionModel.value > contractValue)
                {
                    var data = await _collectionRepository.GetAllCollection(collectionModel.ProjectsID);

                    ViewData["collection"] = data;
                    ViewBag.projects       = new SelectList(await _projectRepository.GetProjects(), "ID", "Title");
                    return(RedirectToAction(nameof(AddNewCollection), new { isSuccess = true, projectId = collectionModel.ProjectsID, isExeed = true, remainedBudget = contractValue - curentCollectionBudget }));
                }
            }

            if (ModelState.IsValid)
            {
                int id = await _collectionRepository.AddNewCollection(collectionModel);

                if (id > 0)
                {
                    return(RedirectToAction(nameof(AddNewCollection), new { isSuccess = true, projectId = collectionModel.ProjectsID }));
                }
            }

            ViewBag.projects = new SelectList(await _projectRepository.GetProjects(), "ID", "Title");
            //ViewData["collection"] = new CollectionModel() { ProjectsID = collectionModel.ProjectsID };

            var data1 = await _collectionRepository.GetAllCollection(collectionModel.ProjectsID);

            ViewData["collection"] = data1;

            return(View());
        }