コード例 #1
0
        public async Task <IActionResult> AddTestimony()
        {
            var testimonyDTO = new TestimonyDTO
            {
                OutputHandler = new OutputHandler
                {
                    IsErrorOccured = false
                }
            };

            testimonyDTO.TestimonyDate = DateTime.Now.AddHours(2);
            return(View(testimonyDTO));
        }
コード例 #2
0
        public async Task <IActionResult> Update(TestimonyDTO testimony)
        {
            var output = await _testimonyService.UpdateTestimony(testimony);

            if (output.IsErrorOccured)
            {
                return(BadRequest(output));
            }
            else
            {
                return(Ok(output));
            }
        }
コード例 #3
0
        public async Task <OutputHandler> UpdateTestimony(TestimonyDTO testimonyDTO)
        {
            try
            {
                if (testimonyDTO.ImgBytes == null)
                {
                    testimonyDTO.ImageUrl = testimonyDTO.ImageUrl;
                }
                else
                {
                    var outputhandler = await FileHandler.SaveFileFromByte(testimonyDTO.ImgBytes, testimonyDTO.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"
                        });
                    }
                    testimonyDTO.ImageUrl = outputhandler.ImageUrl;
                }
                var mapped = new AutoMapper <TestimonyDTO, Testimony>().MapToObject(testimonyDTO);
                await _testimonyRepository.UpdateAsync(mapped);

                await _testimonyRepository.SaveChangesAsync();

                return(new OutputHandler
                {
                    IsErrorOccured = false,
                    Message = "Testimony Updated Successfully"
                });
            }
            catch (Exception ex)
            {
                return(StandardMessages.getExceptionMessage(ex));
            }
        }
コード例 #4
0
        public async Task <IActionResult> UpdateTestimony(int testimonyId)
        {
            var requestUrl   = $"{BaseUrl}{apiUriTestimony}/GetTestimony?testimonyId={testimonyId}";
            var testimonyDTO = new TestimonyDTO
            {
                OutputHandler = new OutputHandler
                {
                    IsErrorOccured = false
                }
            };

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

                if (result.StatusCode == HttpStatusCode.OK)
                {
                    testimonyDTO = await result.Content.ReadAsAsync <TestimonyDTO>();

                    var outputHandler = new OutputHandler
                    {
                        IsErrorOccured = true
                    };
                    testimonyDTO.OutputHandler = outputHandler;
                }
                else
                {
                    testimonyDTO.OutputHandler = await result.Content.ReadAsAsync <OutputHandler>();
                }
            };



            return(View(testimonyDTO));
        }
コード例 #5
0
        public async Task <IActionResult> UpdateTestimony(TestimonyDTO testimonyDTO, IFormFile artwork)
        {
            try
            {
                var user = await StaticDataHandler.GetSessionDetails();

                testimonyDTO.ModifiedBy   = user.Username;
                testimonyDTO.ModifiedDate = DateTime.Now.AddHours(2);
                if (ModelState.IsValid)
                {
                    if (artwork == null)
                    {
                    }
                    else
                    {
                        var fileUploadResult = await StaticDataHandler.fileUpload(artwork, FolderName);

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


                        var result = await client.PutAsJsonAsync(client.BaseAddress, testimonyDTO);

                        if (result.StatusCode == HttpStatusCode.OK)
                        {
                            return(RedirectToAction("ManageTestimonies"));
                        }
                        else if (result.StatusCode == HttpStatusCode.Unauthorized)
                        {
                            testimonyDTO.OutputHandler = new OutputHandler
                            {
                                IsErrorOccured = true,
                                Message        = "You're not Authorized to perfom this task"
                            };
                        }
                        else
                        {
                            testimonyDTO.OutputHandler = await result.Content.ReadAsAsync <OutputHandler>();
                        }
                    };
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message != null)
                {
                    testimonyDTO.OutputHandler = new OutputHandler {
                        IsErrorOccured = true, Message = ex.InnerException.Message
                    };
                }
                else
                {
                    testimonyDTO.OutputHandler = new OutputHandler {
                        IsErrorOccured = true, Message = ex.Message
                    };
                }
            }
            //IEnumerable<SermonCategoryDTO> sermonCategories = await StaticDataHandler.GetSermonCategory(BaseUrl);
            //ministryArm.SermonCategories = sermonCategories;
            return(View(testimonyDTO));
        }