Beispiel #1
0
 public void Insert(Member member)
 {
     throw new NotImplementedException();
 }
Beispiel #2
0
 public void Update(Member member)
 {
     throw new NotImplementedException();
 }
 private string GetAdminAlertDesc(bool isUserInReferrerRole, Member member, DateTime currDate)
 {
     if (isUserInReferrerRole)
     {
         return member.MemberName + " record has been submitted " + " on " + currDate.ToShortDateString() + " ready for processing";
     }
     else
     {
         return member.MemberName + " record has been submitted " + " on " + currDate.ToShortDateString();
     }
 }
        private void CreateFundingResponsibilityOnTheFly(Member member)
        {
            if (member.FundingResponsibilityId == 3 &&
                member.OtherFundingResponsibility != null && member.OtherFundingResponsibility.Trim().Length > 0)
            {
                var newBorough = new FundingResponsibility
                {
                    FundingResponsibilityName = member.OtherFundingResponsibility.Trim()
                };
                _unitOfWork.FundingResponsibilityRepository.Insert(newBorough);

                member.FundingResponsibilityId = newBorough.FundingResponsibilityId;
            }
        }
        private void InsertNotes(Member member)
        {
            if (member.Note != null)
            {
                var notes = new Notes
                {
                    NotesDesc = member.Note,
                    MemberId = member.MemberId,
                    BroadCastAsAlert = member.BroadCastAsAlert,
                    AlertValidDate = member.AlertValidDate,
                    NotesCreateDate = DateTime.UtcNow,
                    NotesCreatedBy = User.Identity.Name
                };

                _unitOfWork.NotesRepository.Insert(notes);
                _unitOfWork.Save();
            }
        }
        private void InsertAdminAlert(Member member, bool isUserInReferrerRole)
        {
            if (_isSubmit == false) return;
            
            var currDate = Convert.ToDateTime(DateTime.UtcNow.ToShortDateString());
            AdminAlert alert = null;

            //1. Find if alert for this member has already been generated
            var resultSet = _unitOfWork.AdminAlertRepository.Get(x => x.MemberId == member.MemberId);
            var adminAlerts = resultSet as IList<AdminAlert> ?? resultSet.ToList();
            if (adminAlerts.Any())
            {
                // If yes then update AlertCreateDate & AlertValid Date
                alert = adminAlerts.ToList()[0];

                //Before doing that check if Member Induction date is provided then set alert dates to two days back else do nothing
                //TODO : This is just a heck to the system as per requirement in doc version 4.1. Need more eleborate solution like intruducing bool var in db indicate to show alert or not or something like that
                if (member.InductionDate.HasValue && member.InductionDate.Value != null)
                {
                    alert.AlertCreatedOn = currDate.AddDays(-2);
                    alert.AlertValidDate = currDate.AddDays(-2);
                }
                else
                {
                    alert.AlertCreatedOn = currDate;
                    alert.AlertValidDate = currDate;
                }

                alert.AlertDesc = GetAdminAlertDesc(isUserInReferrerRole, member, currDate);
                _unitOfWork.AdminAlertRepository.Update(alert);
            }
            else
            {
                //If No, then insert alert
                alert = new AdminAlert
                {
                    AlertDesc = GetAdminAlertDesc(isUserInReferrerRole, member, currDate),
                    MemberId = member.MemberId,
                    AlertValidDate = currDate,
                    AlertCreatedOn = currDate,
                    AlertCreatedBy = User.Identity.Name,
                    //Notes: this will be an enum in future for storing other types of alerts
                    AlertType = 1
                };
                _unitOfWork.AdminAlertRepository.Insert(alert);
            }
            
            _unitOfWork.Save();
        }
        private Member AddNotesToMember(Member member)
        {
            IEnumerable<Notes> notes;
            if (member.MemberId > 0)
            {
                notes = _unitOfWork.NotesRepository.Get(filter: x => x.MemberId == member.MemberId,
                    orderBy: x => x.OrderByDescending(y => y.NotesCreateDate));
            }
            else
            {
                notes = new List<Notes>
                {
                    new Notes
                        {
                            AlertValidDate = DateTime.Today,
                            BroadCastAsAlert = false,
                            Member = member,
                            NotesCreateDate = DateTime.UtcNow,
                            NotesDesc = string.Empty
                        }
                };
            }

            if (member.Notes == null)
            {
                member.Notes = new Collection<Notes>();
                member.Notes.AddRange(notes);
            }

            return member;
        }
        /// <summary>
        /// Adds any new uploaded file to the file collection later saved to database
        /// </summary>
        /// <param name="member"></param>
        private void UploadFiles(Member member)
        {
            if (member.Files == null || !member.Files.Any())
            {
                return;
            }

            member.BinaryFilesList = new List<BinaryFile>();

            foreach (var item in member.Files)
            {
                if(item == null)
                    continue;   //that means there is no file uploaded
                var filename = item.FileName.Substring(item.FileName.LastIndexOf("\\", StringComparison.InvariantCulture) + 1);

                var extension = filename.Substring(filename.LastIndexOf(".", System.StringComparison.Ordinal) + 1);

                var uploadedFile = new byte[item.InputStream.Length];
                item.InputStream.Read(uploadedFile, 0, uploadedFile.Length);

                var binaryFile = new BinaryFile
                {
                    FileContent = uploadedFile,
                    FileName = filename,
                    FileExtension = extension,
                    MemberId = member.MemberId
                };

                _unitOfWork.BinaryFileRepository.Insert(binaryFile);
                
                //member.BinaryFilesList.Add(binaryFile);
            }

            _unitOfWork.Save();
        }
        //private IEnumerable<SelectListItem> GetGroupedEthnicitySelectList(int ethnicityId)
        //{
        //    var ethnicity =  _unitOfWork.EthinicityRepository.Get().OrderBy(t => t.GroupId);
        //    return new SelectList(ethnicity, "EthnicityId", "EthnicityName", selectedValue);
        //    //.Select(t => new GroupedSelectListItem
        //    //{
        //    //    GroupKey = t.GroupId.ToString(CultureInfo.InvariantCulture),
        //    //    GroupName = t.GroupName,
        //    //    Text = t.EthnicityName,
        //    //    Value = t.EthnicityId.ToString(CultureInfo.InvariantCulture),
        //    //    Selected = (t.EthnicityId == ethnicityId)
        //    //});
        //}

        private void UpdateMemberAttendanceRatesToDefault(Member member)
        {
            foreach (var item in member.CurrentWeekAttendances)
            {
                item.MondayRate = (decimal)1.01;
                item.TuesdayRate = (decimal)1.01;
                item.WednesdayRate = (decimal)1.01;
                item.ThursdayRate = (decimal)1.01;
                item.FridayRate = (decimal)1.01;
                item.FridayRate = (decimal)1.01;
                item.SaturdayRate = (decimal)1.01;
                item.SundayRate = (decimal)1.01;
            }
        }
 private void AddViewDataSelectLists(Member member)
 {
     ViewBag.GenderId = GetGenderSelectList(member.GenderId);
     ViewBag.AgentId = GetUserSelectList(member.AgentId);
     ViewBag.LivingAreaId = GetLivingAreaSelectList(member.LivingAreaId);
     ViewBag.GroupedEthnicityId = member.EthnicityId;
     ViewBag.NominationId = GetNominationSelectList(member.NominationId);
     ViewBag.FundingResponsibilityId = GetFundingResponsibilitySelectList(member.FundingResponsibilityId);
     ViewBag.MemberRoleId = GetMemberRoleSelectList(member.MemberRoleId);
     ViewBag.SexualOrientationId = GetSexualOrientationSelectList(member.SexualOrientationId);
     ViewBag.RefereeId = GetAllRefereeSelectList(member.AgentId);
     ViewBag.EthnicityId = GetEthnicitySelectList(member.EthnicityId);
     ViewBag.ReferralTypeId = GetReferralTypeSelectList(member.ReferralTypeId);
     if (member.ProjectMembership == null)
     {
         member.ProjectMembership = new ProjectMembership { Projects = new List<Project>() };
     }
 }
        private Member AddMemberToProjectDetails(Member member)
        {
            var memberToProjects = _unitOfWork.MemberToProjectsRepository.Get(
                filter: x => x.MemberId == member.MemberId && x.IsAssigned && member.IsSubmit, includeProperties: "Project").ToList();

            if (memberToProjects.Count > 0)
            {
                member.ProjectMembership = new ProjectMembership {Projects = new List<Project>()};
                foreach (var item in memberToProjects)
                {
                    item.Project.AssignProjectToMemberNow = true;
                    item.Project.ProjectAlreadyAssigned = true;
                    member.ProjectMembership.Projects.Add(item.Project);
                    member.MemberRoleId = item.MemberRoleId;
                }
            }

            var allprojects = _unitOfWork.ProjectRepository.Get(); 
            foreach (var item in allprojects)
            {
                //check if current project already exists in project membership
                //if yes then do not add else add with default valeus
                if (member.ProjectMembership != null)
                {
                    var existingProjects =
                        member.ProjectMembership.Projects.Where(x => x.ProjectId == item.ProjectId).ToList();
                    if (existingProjects.Count == 0)
                    {
                        item.AssignProjectToMemberNow = false;
                        item.ProjectAlreadyAssigned = false;
                        member.ProjectMembership.Projects.Add(item);
                    }
                }
                else
                {
                    member.ProjectMembership = new ProjectMembership { Projects = new List<Project>() };
                    item.AssignProjectToMemberNow = false;
                    item.ProjectAlreadyAssigned = false;
                    member.ProjectMembership.Projects.Add(item);
                }

            }

            if (member.ProjectMembership == null)
            {
                member.ProjectMembership = new ProjectMembership {Projects = new List<Project>()};
            }
            return member;
        }
 private Member AddAgentDetailsToMember(Member member)
 {
     UserProfile user;
     if (member.MemberId <= 0)
     {
         user = GetCurrentUser();
     }
     else
     {
         user = _unitOfWork.UserRepository.GetById(member.AgentId);
         user.Password = "******";
         user.FullName = user.FirstName + " " + user.LastName;
     }
     user.RelationshipWithApplicant = member.RelationshipToClient;
     member.AgentDetails = user;
     
     return member;
 }
 public ActionResult Submit(Member member)
 {
     if (ModelState.IsValid)
     {
         _isSubmit = true;
         member.ModifiedBy = GetCurrentUserName();
         member.ModifiedOn = GetCurrentDate();
         if (member.MemberId > 0)
         {
             Edit(member);
         }
         else
         {
             Create(member);
         }
     }
     return RedirectToAction("Index");
 }
        public ActionResult Edit(Member member)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var isUserInReferrerRole = User.IsInRole(Role.Referrer.ToString());
                    //member.AgentDetails = null;
                    member.ModifiedBy = GetCurrentUserName();
                    member.ModifiedOn = GetCurrentDate();
                    if (member.AgentId == 0)
                    {
                        member.AgentId = GetCurrentUserId();
                    }

                    if (_isSubmit)
                    {
                        member.IsSubmit = true;
                    }
                    using (var scope = new TransactionScope())
                    {
                        try
                        {
                            //get agent user profile
                            var agentDetails = _unitOfWork.UserRepository.GetById(member.AgentId);
                            var relationshipWithApplicant = member.AgentDetails.RelationshipWithApplicant;
                            member.RelationshipToClient = relationshipWithApplicant;
                            member.AgentDetails = agentDetails;

                            CreateFundingResponsibilityOnTheFly(member);

                            _unitOfWork.MemberRepository.Update(member);
                            _unitOfWork.Save();

                            InsertNotes(member);

                            UploadFiles(member);
                            
                            InsertAdminAlert(member, isUserInReferrerRole);
                            

                            scope.Complete();
                        }
                        catch (Exception ex)
                        {
                            scope.Dispose();
                            //Log the error (uncomment dex variable name after DataException and add a line here to write a log.
                            ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");

                            //TODO: implement some logging and exception handling here
                            throw new Exception(ex.Message);
                        }
                    }

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

            AddViewDataSelectLists(member);

            return View(member);
        }
        public ActionResult Create(Member member)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var isUserInReferrerRole = User.IsInRole(Role.Referrer.ToString());

                    //Validate if Ethnicity is of AnyOther type, then check if some value in 'Other (please specify) is present'
                    //AND if not then set the error message back to the user
                    if ((member.GroupedEthnicityId == (int) EthnicityEnum.OtherWhiteBackground ||
                         member.GroupedEthnicityId == (int) EthnicityEnum.AnyOtherBlackbackground ||
                         member.GroupedEthnicityId == (int) EthnicityEnum.AnyOtherMixedMultipleEthnicBackground ||
                         member.GroupedEthnicityId == (int) EthnicityEnum.AnyotherAsianBackground ||
                         member.GroupedEthnicityId == (int) EthnicityEnum.Other) &&
                        string.IsNullOrWhiteSpace(member.OtherSpecify))
                    {
                        //RAISE ERROR AND SET  OTHER AS REQUIRED FIELD
                        ViewBag.Error = "[Monitoring Information] Select a valid value from Ethnicity or provide input in 'Other (Please specify)' input box";

                        AddViewDataSelectLists(member);

                        //PutTypeDropDownInto(member);
                        return View(member);

                    }

                    var currentDate = GetCurrentDate();
                    member.FormSubmitDate = currentDate;
                    member.ApplicationDate = member.FormSubmitDate;
                    member.CreatedBy = GetCurrentUserName();
                    member.CreatedOn = currentDate;
                    if (member.AgentId == 0)
                    {
                        member.AgentId = GetCurrentUserId();                        
                    }

                    if (_isSubmit)
                    {
                        member.IsSubmit = true;
                    }

                    using (var scope = new TransactionScope())
                    {
                        try
                        {
                            //get agent user profile
                            var agentDetails = _unitOfWork.UserRepository.GetById(member.AgentId);
                            var relationshipWithApplicant = member.AgentDetails.RelationshipWithApplicant;
                            member.AgentDetails = agentDetails;
                            member.AgentDetails.RelationshipWithApplicant = relationshipWithApplicant;
                            member.RelationshipToClient = relationshipWithApplicant;
                            member.AgentDetails.Password = "******";
                            if (member.GroupedEthnicityId != null) member.EthnicityId = member.GroupedEthnicityId.Value;

                            CreateFundingResponsibilityOnTheFly(member);
                           
                            _unitOfWork.MemberRepository.Insert(member);
                            _unitOfWork.Save();

                            InsertNotes(member);

                            UploadFiles(member);

                            
                            InsertAdminAlert(member, isUserInReferrerRole);
                            

                            scope.Complete();

                        }
                        catch (DbEntityValidationException e)
                        {
                            foreach (var eve in e.EntityValidationErrors)
                            {
                                //Utility.WriteToLog("MembershipDataController.Create() : " + ex.Message, "Error");
                                Utility.WriteToLog(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State), "Error");
                                foreach (var ve in eve.ValidationErrors)
                                {
                                    Utility.WriteToLog(string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage), "Error");
                                }
                            }
                            throw;
                        }
                        catch (Exception ex)
                        {
                            scope.Dispose();
                            ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                            Utility.WriteToLog("MembershipDataController.Create() : " + ex, "Error");
                            throw;
                        }
                    }

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

            AddViewDataSelectLists(member);

            //PutTypeDropDownInto(member);
            return View(member);
        }