public ActionResult Index(URLInfo urlInfo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    HttpResponseMessage response = new HttpResponseMessage();
                    if (string.IsNullOrEmpty(urlInfo.LongURL))
                    {
                        return(View());
                    }
                    else
                    {
                        ProcessURLController processURL = new ProcessURLController();
                        response = processURL.ShortenURL(urlInfo);


                        return(View(urlInfo));
                    }
                }

                return(View(urlInfo));
            }
            catch (Exception ex)
            {
                ServiceLocator.ErrorLogger("NEW ERROR LINE : URLShortner/Index | " + DateTime.Now + " | Error:  " + ex.ToString());

                return(View());
            }
        }
        // GET: Trackclicks
        public ActionResult Index(string u)
        {
            try
            {
                if (!string.IsNullOrEmpty(u))
                {
                    URLInfo info = new URLInfo();
                    Uri     uri  = new Uri(u);
                    ProcessURLController processURL = new ProcessURLController();
                    info = processURL.GetURLInfo(uri.AbsolutePath.TrimStart('/'), false);

                    return(View(info));
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ServiceLocator.ErrorLogger("NEW ERROR LINE : Trackclicks/Index | " + DateTime.Now + " | Error:  " + ex.ToString());

                return(View());
            }
        }
Example #3
0
        public HttpResponseMessage GetURLDetails(string shorturl)
        {
            ApiGetURLDetailsResponseMessage response = new ApiGetURLDetailsResponseMessage();

            try
            {
                if (!string.IsNullOrEmpty(shorturl))
                {
                    URLInfo info = new URLInfo();
                    Uri     uri  = new Uri(shorturl);
                    ProcessURLController processURL = new ProcessURLController();
                    info = processURL.GetURLInfo(uri.AbsolutePath.TrimStart('/'), false);

                    response.Result           = "SUCCESS";
                    response.Responsecode     = HttpStatusCode.OK;
                    response.URLInfo          = info;
                    response.Errorcause       = "";
                    response.Errordescription = "";
                }
                else
                {
                    response.Result           = "FAIL";
                    response.Responsecode     = HttpStatusCode.Forbidden;
                    response.URLInfo          = null;
                    response.Errorcause       = "Not a valid URL!";
                    response.Errordescription = "Please enter a valid URL";
                }
            }
            catch (Exception ex)
            {
                response.Result           = "FAIL";
                response.Responsecode     = HttpStatusCode.InternalServerError;
                response.URLInfo          = null;
                response.Errorcause       = "Internal Server Error";
                response.Errordescription = ex.Message;

                ServiceLocator.ErrorLogger("NEW ERROR LINE : ProcessURL/GetURLDetails | " + DateTime.Now + " | Error:  " + ex.ToString());
            }


            string errorMessage = JsonConvert.SerializeObject(response);

            var httpResponse = new HttpResponseMessage(response.Responsecode);

            httpResponse.Content = new StringContent(errorMessage, System.Text.Encoding.UTF8, "application/json");
            return(httpResponse);
        }
        public ActionResult RedirectToURL(string shortCode)
        {
            try
            {
                URLInfo info = new URLInfo();
                ProcessURLController processURL = new ProcessURLController();
                info = processURL.GetURLInfo(shortCode, true);

                if (info != null && !string.IsNullOrEmpty(info.LongURL))
                {
                    return(Redirect(info.LongURL));
                }
                else
                {
                    return(Redirect(ConfigurationManager.AppSettings["redirecturl"].ToString()));
                }
            }
            catch (Exception ex)
            {
                ServiceLocator.ErrorLogger("NEW ERROR LINE : URLShortner/RedirectToURL | " + DateTime.Now + " | Error:  " + ex.ToString());

                return(Redirect(ConfigurationManager.AppSettings["redirecturl"].ToString()));
            }
        }