public async Task <IActionResult> EditTeamMember(int teamMemberId)
        {
            var            requestUrl = $"{BaseUrl}{apiUriTeamMembers}/GetTeamMemberDetails?teamMemberId={teamMemberId}";
            TeamMembersDTO teamMember = new TeamMembersDTO();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(requestUrl);
                HttpResponseMessage response = await client.GetAsync(requestUrl);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    teamMember = await response.Content.ReadAsAsync <TeamMembersDTO>();
                }
                else
                {
                    teamMember.OutputHandler = await response.Content.ReadAsAsync <OutputHandler>();
                }
                teamMember.Branches = await StaticDataHandler.GetBranches(BaseUrl);

                teamMember.Positions = await StaticDataHandler.GetPositions(BaseUrl);

                teamMember.MinistryArms = await StaticDataHandler.GetMinistryArmsAsync(BaseUrl);
            };

            teamMember.Branches = await StaticDataHandler.GetBranches(BaseUrl);

            teamMember.Positions = await StaticDataHandler.GetPositions(BaseUrl);

            teamMember.MinistryArms = await StaticDataHandler.GetMinistryArmsAsync(BaseUrl);

            teamMember.OldImageUrl      = teamMember.ImageUrl;
            teamMember.CurrentImageName = Path.GetFileName(teamMember.ImageUrl);
            return(View(teamMember));
        }
Example #2
0
        public async Task <IActionResult> EditOfficer(int personalDetailsId, ResultHandler resultHandler = null)
        {
            var role     = HttpContext.Session.GetInt32(SessionKeyRole);
            var username = HttpContext.Session.GetString(SessionUserName);

            if (username == null)
            {
                HttpContext.Session.SetString(SessionUserName, username);
            }

            if (resultHandler.Result != null)
            {
                personalDetailsId = (int)resultHandler.Result;
            }

            if (username == null && role != 1)
            {
                return(RedirectToAction("Login", "Accounts"));
            }
            UserDTO user       = new UserDTO();
            var     requestUrl = $"{BaseUrl}{apiUri}/GetUserById?personId={personalDetailsId}";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(requestUrl);
                HttpResponseMessage response = await client.GetAsync(requestUrl);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    user = await response.Content.ReadAsAsync <UserDTO>();
                }
                ;
            };

            IEnumerable <Branch> branches = await StaticDataHandler.GetBranches(BaseUrl);

            IEnumerable <Positions> positions = await StaticDataHandler.GetPositions(BaseUrl);

            IEnumerable <Roles> roles = await StaticDataHandler.GetRoles(BaseUrl);

            user.Branches  = branches;
            user.Positions = positions;
            user.Roles     = roles;

            //True - means its  comming from edit and something went wrong
            if (resultHandler.IsErrorOccured == true)
            {
                user.IsErrorOccured = true;
                user.Message        = "The system failed to delete the record, please contact inform Technical Administrator";
            }
            return(View(user));
        }
        public async Task <IActionResult> AddTeamMember()
        {
            IEnumerable <BranchDTO> branches = await StaticDataHandler.GetBranches(BaseUrl);

            IEnumerable <PositionDTO> positions = await StaticDataHandler.GetPositions(BaseUrl);

            IEnumerable <MinistryArmDTO> ministryArms = await StaticDataHandler.GetMinistryArmsAsync(BaseUrl);

            var teamMemberDTO = new TeamMembersDTO
            {
                Branches     = branches,
                Positions    = positions,
                MinistryArms = ministryArms
            };

            return(View(teamMemberDTO));
        }
        public async Task <IActionResult> TeamMembers()
        {
            var           requestUrl  = $"{BaseUrl}{apiUriTeamMembers}/GetTeamMembers";
            TeamMembersVM teamMembers = new TeamMembersVM(_configuration);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(requestUrl);
                HttpResponseMessage response = await client.GetAsync(requestUrl);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    teamMembers.TeamMembersDTO = await response.Content.ReadAsAsync <IEnumerable <TeamMembersDTO> >();
                }
                ;
            };
            teamMembers.BranchDTO = await StaticDataHandler.GetBranches(BaseUrl);

            return(View(teamMembers));
        }
        //public async Task<IActionResult> TeamMembersByCategory(string name, int id)
        //{
        //    var requestUrl = $"{BaseUrl}{apiUriTeamMembers}/TeamMembersByCategory?categoryId={id}";
        //    TeamMembersVM teamMembers = new TeamMembersVM();
        //    using (var client = new HttpClient())
        //    {
        //        client.BaseAddress = new Uri(requestUrl);
        //        HttpResponseMessage response = await client.GetAsync(requestUrl);

        //        if (response.StatusCode == HttpStatusCode.OK)
        //        {
        //            teamMembers.TeamMembersDTO = await response.Content.ReadAsAsync<IEnumerable<TeamMembersDTO>>();

        //        };

        //    };
        //    teamMembers.BranchDTO = await StaticDataHandler.GetBranches(BaseUrl);
        //   // teamMembers.PageHeader = name; //This is the category name carried over from the teamMember details page
        //    return View(teamMembers);
        //}

        public async Task <IActionResult> TeamMemberDetails(int teamMemberId)
        {
            var            requestUrl = $"{BaseUrl}{apiUriTeamMembers}/GetTeamMemberDetails?teamMemberId={teamMemberId}";
            TeamMembersDTO teamMember = new TeamMembersDTO();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(requestUrl);
                HttpResponseMessage response = await client.GetAsync(requestUrl);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    teamMember = await response.Content.ReadAsAsync <TeamMembersDTO>();
                }
                ;
                teamMember.Branches = await StaticDataHandler.GetBranches(BaseUrl);

                var filteredbranches = teamMember.Branches.Where(x => x.BranchId == teamMember.BranchId);
                teamMember.BranchName = filteredbranches.Select(p => p.BranchName).ToString();
            };
            return(View(teamMember));
        }
Example #6
0
        public async Task <IActionResult> Register(string message)
        {
            if (message != null)
            {
                ViewBag.message = message;
            }

            IEnumerable <Branch> branches = await StaticDataHandler.GetBranches(BaseUrl);

            IEnumerable <Positions> positions = await StaticDataHandler.GetPositions(BaseUrl);

            IEnumerable <Roles> roles = await StaticDataHandler.GetRoles(BaseUrl);

            var user = new UserDTO
            {
                Branches  = branches,
                Positions = positions,
                Roles     = roles,
            };

            return(View(user));
        }
        public async Task <IActionResult> EditTeamMember(TeamMembersDTO teamMember, IFormFile artwork)
        {
            try
            {
                var user = await StaticDataHandler.GetSessionDetails();

                teamMember.ModifiedBy   = user.Username;
                teamMember.ModifiedDate = DateTime.Now.AddHours(2);

                if (ModelState.IsValid)
                {
                    if (artwork == null)
                    {
                    }
                    else
                    {
                        var fileUploadResult = await StaticDataHandler.fileUpload(artwork, FolderName);

                        if (fileUploadResult.IsErrorOccured)
                        {
                            return(View(teamMember.OutputHandler = new OutputHandler
                            {
                                IsErrorOccured = true,
                                Message = "Something went wrong"
                            }));
                        }
                        else
                        {
                            teamMember.Artwork  = (byte[])fileUploadResult.Result; //return the byte data
                            teamMember.Filename = artwork.FileName;
                        }
                    }
                    var requestUrl = $"{BaseUrl}{apiUriTeamMembers}/EditTeamMember";
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(requestUrl);
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", user.Token);
                        var result = await client.PostAsJsonAsync(client.BaseAddress, teamMember);

                        if (result.StatusCode == HttpStatusCode.OK)
                        {
                            return(RedirectToAction("TeamMembersForAdmin"));
                        }
                        else if (result.StatusCode == HttpStatusCode.Unauthorized)
                        {
                            teamMember.OutputHandler = new OutputHandler
                            {
                                IsErrorOccured = true,
                                Message        = "You're not Authorized to perfom this task"
                            };
                        }
                        else
                        {
                            teamMember.OutputHandler = await result.Content.ReadAsAsync <OutputHandler>();
                        };
                    };
                }
                else
                {
                    teamMember.Branches = await StaticDataHandler.GetBranches(BaseUrl);

                    teamMember.Positions = await StaticDataHandler.GetPositions(BaseUrl);

                    teamMember.MinistryArms = await StaticDataHandler.GetMinistryArmsAsync(BaseUrl);
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message != null)
                {
                    teamMember.OutputHandler = new OutputHandler {
                        IsErrorOccured = true, Message = ex.InnerException.Message
                    };
                }
                else
                {
                    teamMember.OutputHandler = new OutputHandler {
                        IsErrorOccured = true, Message = ex.Message
                    };
                }
            }
            IEnumerable <BranchDTO> branches = await StaticDataHandler.GetBranches(BaseUrl);

            teamMember.MinistryArms = await StaticDataHandler.GetMinistryArmsAsync(BaseUrl);

            teamMember.Positions = await StaticDataHandler.GetPositions(BaseUrl);

            teamMember.CurrentImageName = Path.GetFileName(teamMember.ImageUrl);

            teamMember.Branches = branches;
            return(View(teamMember));
        }
Example #8
0
        public async Task <IActionResult> Register(UserDTO user)
        {
            if (user.DateOfBirth > DateTime.UtcNow.AddHours(2))
            {
                string error = "Date cannot be from the future";
                return(RedirectToAction("Register", new { message = error }));
            }


            if (user.DateOfBirth == DateTime.UtcNow.AddHours(2))
            {
                string error = "Date cannot be today";
                return(RedirectToAction("Register", new { message = error }));
            }

            int age = DateTime.UtcNow.Year - user.DateOfBirth.Year;

            if (age < 16)
            {
                string error = "Minimum years is 16 years old";
                return(RedirectToAction("Register", new { message = error }));
            }

            OutputHandler resultHandler = new OutputHandler();

            if (user.Password == user.ConfirmPassword)
            {
                if (ModelState.IsValid)
                {
                    var requestUrl = $"{BaseUrl}{apiUri}/CreateUser";
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(requestUrl);
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                        user.RoleId = 2;


                        var result = await client.PostAsJsonAsync(client.BaseAddress, user);

                        if (result.StatusCode == HttpStatusCode.OK)
                        {
                            if (user.PositionId == 3)
                            {
                                return(RedirectToAction("ManageUsers"));
                            }
                            else
                            {
                                return(RedirectToAction("ManageOfficers"));
                            }
                        }
                        else
                        {
                            resultHandler = await result.Content.ReadAsAsync <OutputHandler>();

                            if (resultHandler.Message != null)
                            {
                                user.Message = resultHandler.Message;
                            }

                            IEnumerable <Branch> branches = await StaticDataHandler.GetBranches(BaseUrl);

                            IEnumerable <Positions> positions = await StaticDataHandler.GetPositions(BaseUrl);

                            IEnumerable <Roles> roles = await StaticDataHandler.GetRoles(BaseUrl);

                            user.Branches          = branches;
                            user.Positions         = positions;
                            user.Roles             = roles;
                            user.IsOfficerCreation = user.IsOfficerCreation;

                            return(View(user));
                        }
                    };
                }
                else
                {
                    IEnumerable <Branch> branches = await StaticDataHandler.GetBranches(BaseUrl);

                    IEnumerable <Positions> positions = await StaticDataHandler.GetPositions(BaseUrl);

                    IEnumerable <Roles> roles = await StaticDataHandler.GetRoles(BaseUrl);

                    user.Branches          = branches;
                    user.Positions         = positions;
                    user.Roles             = roles;
                    user.IsOfficerCreation = user.IsOfficerCreation;

                    return(View(user));
                }
            }
            else
            {
                ModelState.AddModelError("", "Password does do not match");
                ;
                IEnumerable <Branch> branches = await StaticDataHandler.GetBranches(BaseUrl);

                IEnumerable <Positions> positions = await StaticDataHandler.GetPositions(BaseUrl);

                IEnumerable <Roles> roles = await StaticDataHandler.GetRoles(BaseUrl);

                user.Branches          = branches;
                user.Positions         = positions;
                user.Roles             = roles;
                user.IsOfficerCreation = user.IsOfficerCreation;

                //var user = new UserDTO
                //{
                //    Branches = branches,
                //    Positions = positions,
                //    Roles = roles
                //};
            }
            return(View(user));
        }
Example #9
0
        public async Task <IActionResult> EditOfficer(long personalDetailsId, UserDTO user)
        {
            ResultHandler resultHandler = new ResultHandler();

            if (ModelState.IsValid)
            {
                var requestUrl = $"{BaseUrl}{apiUri}/UpdateUser";
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(requestUrl);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                    user.RoleId = 1;


                    var result = await client.PostAsJsonAsync(client.BaseAddress, user);

                    if (result.StatusCode == HttpStatusCode.OK)
                    {
                        return(RedirectToAction("ManageOfficers"));
                    }
                    else
                    {
                        resultHandler = await result.Content.ReadAsAsync <ResultHandler>();

                        if (resultHandler.IsErrorOccured)
                        {
                            ModelState.AddModelError("", resultHandler.Message);
                        }

                        IEnumerable <Branch> branches = await StaticDataHandler.GetBranches(BaseUrl);

                        IEnumerable <Positions> positions = await StaticDataHandler.GetPositions(BaseUrl);

                        IEnumerable <Roles> roles = await StaticDataHandler.GetRoles(BaseUrl);

                        user.Branches  = branches;
                        user.Positions = positions;
                        user.Roles     = roles;

                        return(View(user));
                    }
                };
            }
            else
            {
                IEnumerable <Branch> branches = await StaticDataHandler.GetBranches(BaseUrl);

                IEnumerable <Positions> positions = await StaticDataHandler.GetPositions(BaseUrl);

                IEnumerable <Roles> roles = await StaticDataHandler.GetRoles(BaseUrl);

                user.Branches  = branches;
                user.Positions = positions;
                user.Roles     = roles;
                return(View(user));
            }


            return(View(user));
        }