Esempio n. 1
0
        public ActionResult Edit(int id)
        {
            var requirement = _requirementRepository.Get(id);

            if (requirement == null)
            {
                return(HttpNotFound());
            }

            var mappedTechnologies = _requirementTechnologyMapRepository.GetAllBy(m => m.RequirementId == requirement.Id).Select(m => m.TechnologyId).ToList();

            ViewBag.Technologies     = new MultiSelectList(_technologyRepository.GetAll(), "Id", "Title", mappedTechnologies);
            ViewBag.AssignedToUserId = new SelectList(_userRepository.GetAll("Person"), "Id", "Person.Name", requirement.AssignedToUserId);
            ViewBag.ContactId        = new SelectList(_crmContactRepository.GetAll("Person"), "Id", "Person.Name", requirement.ContactId);
            ViewBag.CategoryId       = new SelectList(_requirementCategoryRepository.GetAll(), "Id", "Title", requirement.CategoryId);
            ViewBag.SourceId         = new SelectList(_crmLeadSourceRepository.GetAll(), "Id", "Title", requirement.SourceId);

            var vm = new EditRequirementViewModel(requirement);

            return(View(vm));
        }
Esempio n. 2
0
        public ActionResult Edit(EditRequirementViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var selectedRequirement = _requirementRepository.Get(vm.Id);

                if (selectedRequirement != null)
                {
                    selectedRequirement.AssignedToUserId = vm.AssignedToUserId;
                    selectedRequirement.ContactId        = vm.ContactId;
                    selectedRequirement.SourceId         = vm.SourceId;
                    selectedRequirement.CategoryId       = vm.CategoryId;
                    selectedRequirement.Title            = vm.Title;
                    selectedRequirement.Description      = vm.Description;
                    selectedRequirement.Url         = vm.Url;
                    selectedRequirement.BillingType = vm.BillingType;
                    selectedRequirement.Budget      = vm.Budget;
                    selectedRequirement.PostedOn    = vm.PostedOn;

                    selectedRequirement.UpdatedByUserId = WebUser.Id;

                    _requirementRepository.Update(selectedRequirement);
                    _unitOfWork.Commit();

                    // Remove the existing mapped Technologies
                    var existingMaps = _requirementTechnologyMapRepository.GetAllBy(m => m.RequirementId == selectedRequirement.Id);
                    foreach (var map in existingMaps)
                    {
                        _requirementTechnologyMapRepository.Delete(map);
                    }

                    _unitOfWork.Commit();

                    // Map the New Technologies
                    if (vm.TechnologyIds != null)
                    {
                        foreach (var technologyId in vm.TechnologyIds)
                        {
                            var newMap = new RequirementTechnologyMap
                            {
                                RequirementId = vm.Id,
                                TechnologyId  = technologyId
                            };
                            _requirementTechnologyMapRepository.Create(newMap);
                        }

                        _unitOfWork.Commit();
                    }

                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.Technologies     = new MultiSelectList(_technologyRepository.GetAll(), "Id", "Title", vm.TechnologyIds);
            ViewBag.AssignedToUserId = new SelectList(_userRepository.GetAll("Person"), "Id", "Person.Name", vm.AssignedToUserId);
            ViewBag.ContactId        = new SelectList(_crmContactRepository.GetAll("Person"), "Id", "Person.Name", vm.ContactId);
            ViewBag.CategoryId       = new SelectList(_requirementCategoryRepository.GetAll(), "Id", "Title", vm.CategoryId);
            ViewBag.SourceId         = new SelectList(_crmLeadSourceRepository.GetAll(), "Id", "Title", vm.SourceId);

            return(View(vm));
        }