Пример #1
0
        public async Task <IActionResult> Create(BannerInformationDto banner)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Index)));
            }
            try
            {
                await _ban.AddBanner(banner);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Пример #2
0
        public async Task <IActionResult> CreateBanner([FromBody] Banner objBanner)
        {
            VaildationMessage = "";
            //Flag for Checking whether new entry has being made
            bool IsAdded = false;

            try
            {
                //Validating Html and if not valid HTMl then  Message is sent back  With Errors
                VaildationMessage = _validator.HtmlValidationMessage(objBanner.Html);

                //Save Method
                // If there is no validation messsge, i.e HTMl is valid and so entry is being made into database
                if (string.IsNullOrEmpty(VaildationMessage))
                {
                    objBanner = await _bannerRepository.AddBanner(objBanner);

                    if (!string.IsNullOrEmpty(objBanner.Id))
                    {
                        IsAdded = true;
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error("Error in CreateBanner method of BannerController :" + Environment.NewLine + ex.StackTrace);
            }

            //Response
            if (!string.IsNullOrEmpty(VaildationMessage)) // Bad request with  Errors in Html is sent back
            {
                return(BadRequest(VaildationMessage));
            }
            else if (IsAdded)
            {
                return(Ok(objBanner)); // Newly created entry
            }
            else
            {
                return(new StatusCodeResult((int)HttpStatusCode.ServiceUnavailable));
            }
        }
Пример #3
0
 public int AddBanner(Banner bannerInfo)
 {
     return(_bannerRepository.AddBanner(bannerInfo));
 }