コード例 #1
0
        public IHttpActionResult AddUrl(UrlViewModel Url)
        {
            return(ExceptionHandler.CallMethod(() =>
            {
                var DashboardService = new DashboardService();
                var role = ((ClaimsIdentity)User.Identity).Claims
                           .Where(c => c.Type == ClaimTypes.Role)
                           .Select(c => c.Value)
                           .FirstOrDefault();
                var result = 0;

                if (role == "Admin")
                {
                    result = DashboardService.AddAdminUrl(Url.Url, Url.Duration, User.Identity.GetUserId());
                }
                else
                {
                    result = DashboardService.AddUrl(Url.Url, Url.Duration, User.Identity.GetUserId());
                }

                if (result == 0)
                {
                    return Json(new { success = true, message = "URL added successfully!" });
                }
                else if (result == 1)
                {
                    return Json(new { success = false, message = "Duplicate URL!" });
                }
                else if (result == 2)
                {
                    return Json(new { success = false, message = "URLs limit succeeded!" });
                }
                else
                {
                    return Json(new { success = false, message = "URL not added!" });
                }
            }, ModelState));
        }