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));
        }
Esempio n. 2
0
        public async Task <IActionResult> AddTeamMember(TeamMembersDTO teamMember)
        {
            var output = await _service.AddTeamMemberAsync(teamMember);

            if (output.IsErrorOccured == true)
            {
                return(BadRequest(output));
            }
            else
            {
                return(Ok(output));
            }
        }
        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));
        }
Esempio n. 4
0
        public async Task <OutputHandler> AddTeamMemberAsync(TeamMembersDTO teamMember)
        {
            var outputhandler = await FileHandler.SaveFileFromByte(teamMember.Artwork, teamMember.Filename, FolderName);

            if (outputhandler.IsErrorOccured)
            {
                if (outputhandler.IsErrorKnown)
                {
                    return(new OutputHandler
                    {
                        IsErrorOccured = true,
                        Message = outputhandler.Message
                    });
                }
                return(new OutputHandler
                {
                    IsErrorOccured = true,
                    Message = "Something went wrong while the system tried to upload the file"
                });
            }
            teamMember.ImageUrl = outputhandler.ImageUrl;


            try
            {
                var MappedTeamMember = new AutoMapper <TeamMembersDTO, TeamMember>().MapToObject(teamMember);
                _teamMemberRepository.CreateEntity(MappedTeamMember);
                await _teamMemberRepository.SaveChangesAsync();

                return(new OutputHandler
                {
                    IsErrorOccured = false,
                    Message = "TeamMember has been created Successsdfully "
                });
            }
            catch (Exception ex)
            {
                var outputHandler = await FileHandler.DeleteFileFromFolder(teamMember.ImageUrl, FolderName);

                return(StandardMessages.getExceptionMessage(ex));
            }
        }
        //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));
        }
        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));
        }
Esempio n. 7
0
        public async Task <OutputHandler> EditTeamMember(TeamMembersDTO teamMember)
        {
            if (teamMember.Artwork == null)
            {
                teamMember.ImageUrl = teamMember.OldImageUrl;
            }
            else
            {
                var outputhandler = await FileHandler.SaveFileFromByte(teamMember.Artwork, teamMember.Filename, FolderName);

                if (outputhandler.IsErrorOccured)
                {
                    if (outputhandler.IsErrorKnown)
                    {
                        return(new OutputHandler
                        {
                            IsErrorOccured = true,
                            Message = outputhandler.Message
                        });
                    }
                    return(new OutputHandler
                    {
                        IsErrorOccured = true,
                        Message = "Something went wrong while the system tried to upload the file"
                    });
                }


                teamMember.ImageUrl = outputhandler.ImageUrl;
            }
            try
            {
                var MappedTeamMember = new AutoMapper <TeamMembersDTO, TeamMember>().MapToObject(teamMember);
                await _teamMemberRepository.UpdateAsync(MappedTeamMember);

                await _teamMemberRepository.SaveChangesAsync();

                if (teamMember.OldImageUrl == null)
                {
                }
                else
                {
                    if (teamMember.Artwork == null) //if Byte[] is null means image is not being updated
                    {
                    }
                    else // only delete if artwork is not null meaning image is being updated
                    //delete old file
                    {
                        var outputHandler = await FileHandler.DeleteFileFromFolder(teamMember.OldImageUrl, FolderName);

                        if (outputHandler.IsErrorOccured) //True means Delete was not successful for some reason
                        {
                            return(new OutputHandler
                            {
                                IsErrorKnown = true,
                                IsErrorOccured = true,
                                Message = "Team Member Details updated successfully, but deleting of old file failed, please alert Techarch Team"
                            });
                        }
                    }
                }
                return(new OutputHandler
                {
                    IsErrorOccured = false,
                    Message = "Team Member has been edited Successsdfully "
                });
            }
            catch (Exception ex)
            {
                return(StandardMessages.getExceptionMessage(ex));
            }
        }