Ejemplo n.º 1
0
        public OperationResult <bool> Delete(int id)
        {
            var technologyMaps = _requirementTechnologyMapRepository.GetAllBy(m => m.RequirementId == id);

            foreach (var map in technologyMaps)
            {
                _requirementTechnologyMapRepository.Delete(map);
            }

            var activities = _requirementActivityRepository.GetAllBy(m => m.RequirementId == id);

            foreach (var activity in activities)
            {
                _requirementActivityRepository.Delete(activity);
            }

            var docs = _requirementDocumentRepository.GetAllBy(m => m.RequirementId == id);

            foreach (var doc in docs)
            {
                _requirementDocumentRepository.Delete(doc);
            }

            _requirementRepository.Delete(id);
            _unitOfWork.Commit();

            return(new OperationResult <bool> {
                Status = true
            });
        }
Ejemplo 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));
        }