Beispiel #1
0
        private string IsDataValid(Project project)
        {
            var errorMessage = new StringBuilder();
            
            //end date cannot be less than start date
            if (project.EndDate.HasValue)
            {
                if (DateTime.Compare(project.EndDate.Value, project.StartDate) < 0)
                {
                    errorMessage.Append("End date cannot be less than start date");
                    errorMessage.Append(Environment.NewLine);
                }
            }

            if (project.SupervisorId <= 0)
            {
                errorMessage.Append("Please select Supervisor");
                errorMessage.Append(Environment.NewLine);
            }

            //max no of participants cannot be less than current members assgined to the project
            var memberAssigned = _unitOfWork.MemberToProjectsRepository.Get(filter: x => x.ProjectId == project.ProjectId);
            if (memberAssigned.Any())
            {
                if (memberAssigned.Count() > project.MaxNoOfParticipants)
                {
                    errorMessage.Append("This project has more assigned member than max no you are setting here. Cannot save");
                    errorMessage.Append(Environment.NewLine);
                }
            }

            return errorMessage.ToString();
        }
Beispiel #2
0
        private MembersToProjectCollection CreateMemberToProjectCollectionObject(Project project)
        {
            var membersToProjectColl = new MembersToProjectCollection();

            membersToProjectColl.Role =
                _unitOfWork.RoleRepository.Get(orderBy: x => x.OrderBy(k => k.MemberRoleName)).ToList();

            var allMembers = _unitOfWork.MemberRepository.Get(filter: f => f.IsSubmit && f.NominationId != 2, orderBy: x => x.OrderBy(k => k.MemberName)).ToList(); //2 == Old Member

            var newMemberList = allMembers.Select(member => new CutDownVersionOfMembers
            {
                MemberId = member.MemberId,
                MemberName = member.MemberName,
                AssignDate = DateTime.UtcNow,
                Rate = new decimal(0.0),
                ProjectId = project.ProjectId,
                MemberAlreadyExists = false,
                MemberToProjectId = 0
            }).ToList();

            membersToProjectColl.Project = project;
            membersToProjectColl.AllCutdownMembers = newMemberList;
            membersToProjectColl.AllMembers = allMembers;

            //var listOfMembersInAllMembersButNotInMemberToProject = new List<CutDownVersionOfMembers>();
            foreach (var item in _unitOfWork.MemberToProjectsRepository.Get())
            {
                var memberToProject = item;
                var isExists =
                    membersToProjectColl.AllCutdownMembers.Where(
                        m => m.MemberId == memberToProject.MemberId && m.ProjectId == memberToProject.ProjectId)
                        .ToList();
                if (isExists.Count > 0)
                {
                    isExists[0].AssignDate = memberToProject.AssignDate;
                    isExists[0].Rate = memberToProject.MemberRate;
                    isExists[0].RoleId = memberToProject.MemberRoleId;
                    isExists[0].MemberAlreadyExists = true;
                    isExists[0].IsAssigned = memberToProject.IsAssigned;
                    isExists[0].MemberToProjectId = memberToProject.MemberToProjectId;
                }

            }
            return membersToProjectColl;
        }
Beispiel #3
0
        public ActionResult Edit(Project project)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var errors = IsDataValid(project);
                    if (errors.Length > 0)
                    {
                        ViewBag.Error = errors;
                    }
                    else
                    {
                        var userName = User.Identity.Name;
                        project.ModifiedBy = userName;
                        project.ModifiedOn = DateTime.UtcNow;

                        _unitOfWork.ProjectRepository.Update(project);
                        _unitOfWork.Save();
                        //db.Entry(project).State = EntityState.Modified;
                        //db.SaveChanges();

                        return RedirectToAction("Index");
                    }
                }
                catch (Exception ex)
                {
                    Utility.WriteToLog("ProjectController.Edit() : " + ex, "Error");
                    throw;
                }
            }

            ViewBag.SupervisorId = GetSupervisorSelectList(project.SupervisorId);
            ViewBag.ClassificationId = GetClassificationSelectList(project.ClassificationId);

            return View(project);
        }