コード例 #1
0
        public async Task <ActionResult> View(int id)
        {
            try
            {
                ViewBag.User_Id    = HttpContext.Session.GetString("User_Id");
                ViewBag.Company_Id = HttpContext.Session.GetString("Company_Id");
                ViewBag.UserName   = HttpContext.Session.GetString("UserName");
                ViewBag.FullName   = HttpContext.Session.GetString("ContactName");

                var  userRoles      = JsonConvert.DeserializeObject <List <VmRoleItem> >(HttpContext.Session.GetString("SelectedRoles"));
                bool isCompanyAdmin = false;
                if (userRoles.Where(e => e.Id == Constants.C_Admin_Role).ToList().Count > 0)
                {
                    isCompanyAdmin = true;
                }
                ViewBag.CompanyAdmin = isCompanyAdmin;

                string User_Id            = HttpContext.Session.GetString("User_Id");
                string Company_Id         = HttpContext.Session.GetString("Company_Id");
                string currentCompanyType = HttpContext.Session.GetString("C_BusinessType");

                var checkPermissionResult = await quotationService.CheckPermissionForQuotation(Convert.ToInt32(Company_Id), Convert.ToInt32(currentCompanyType), Convert.ToInt32(User_Id), id, isCompanyAdmin);

                if (checkPermissionResult.IsSuccess)
                {
                    var result = await quotationService.GetSingleQuotationById(id);

                    int userId = Convert.ToInt32(HttpContext.Session.GetString("User_Id"));
                    int roleId = Convert.ToInt32(Constants.QuotationDefaultRoleId);

                    ViewBag.DocumentOwner = true;
                    if (result.Document.DocumentUserDisplay.Where(e => e.User_Id == userId && e.Roles.Contains(Constants.QuotationDefaultRole)).ToList().Count > 0)
                    {
                        ViewBag.DocumentOwner = true;
                    }
                    return(View(result));
                }
                else
                {
                    TempData["ErrorMessage"] = "You are not authorized to access this Quotation.";
                    return(RedirectToAction("ErrorForUser", "Home"));
                }
            }
            catch (Exception ex)
            {
                TempData["ErrorMessage"] = ex.Message;
                return(RedirectToAction("ErrorForUser", "Home"));
            }
        }