///<summary>
        ///Returns view which contains indent model with: indent data, recalls, responces.
        ///Defines client opportunities to: write recall/responce, choose executor for indent.
        ///</summary>
        public ActionResult ShowIndent(int?id)
        {
            if (TempData["ErrorMessage"] != null)
            {
                ViewBag.ErrorMessage = TempData["ErrorMessage"];
            }

            IndentDTO indentDTO = null;
            int       indentId  = id ?? default(int);

            string cacheKey = "show-indent-" + indentId.ToString();

            indentDTO = HttpContext.Cache[cacheKey] as IndentDTO;

            if (indentDTO == null)
            {
                try
                {
                    indentDTO = _indentService.Get(indentId);
                }
                catch (ValidationException e)
                {
                    return(new HttpStatusCodeResult(404));
                }

                HttpContext.Cache.Insert(cacheKey, indentDTO, null, DateTime.Now.AddSeconds(120), TimeSpan.Zero);
            }

            var    claimIdentity = HttpContext.User.Identity as ClaimsIdentity;
            string role          = "";
            Role?  clientRole    = null;
            int?   clientId      = null;

            if (claimIdentity != null)
            {
                var roleClaim = claimIdentity.FindFirst(ClaimsIdentity.DefaultRoleClaimType);
                if (roleClaim != null)
                {
                    role       = roleClaim.Value.Trim();
                    clientRole = (Role)Enum.Parse(typeof(Role), role);
                }
            }

            var varClientId = Session["Id"];

            if (varClientId != null)
            {
                clientId = Convert.ToInt32(varClientId);
            }

            HelpModelForClientOpportunities clientOpportunities = new HelpModelForClientOpportunities();

            if (clientId != null && clientRole != null)
            {
                clientOpportunities = SetClientOpportunities(indentDTO, clientRole, clientId);
            }

            IndentViewModel indentViewModel = _mapper.Map <IndentViewModel>(indentDTO);

            IndentFullViewModel indentFullViewModel = new IndentFullViewModel()
            {
                indentViewModel     = indentViewModel,
                clientOpportunities = clientOpportunities
            };

            return(View(indentFullViewModel));
        }
        private HelpModelForClientOpportunities SetClientOpportunities(IndentDTO indentDTO, Role?clientRole, int?clientId)
        {
            HelpModelForClientOpportunities clientPossibilities = new HelpModelForClientOpportunities();

            switch (clientRole)
            {
            case Role.Customer:
            {
                if (clientId == indentDTO.Customer.CustomerId)
                {
                    if (indentDTO.Executor == null)
                    {
                        clientPossibilities.customerIsAllowToSelectExecutor = true;
                    }

                    if (indentDTO.Executor != null &&
                        (indentDTO.Recall == null || indentDTO.Recall.CustomerMarkForExecutor == null))
                    {
                        clientPossibilities.customerIsAllowToWriteRecall = true;
                    }
                }
                return(clientPossibilities);
            }

            case Role.Executor:
            {
                if (indentDTO.Executor == null)
                {
                    int         executorId        = clientId ?? default(int);
                    ExecutorDTO clientExecutorDTO = _executorService.GetExecutorPropertiesForEdition(executorId);

                    if (clientExecutorDTO.Categories.Count() > 0)
                    {
                        foreach (Category executorCategory in clientExecutorDTO.Categories)
                        {
                            if (executorCategory.Equals(indentDTO.CategoryId))
                            {
                                clientPossibilities.executorIsAllowToSendResponce = true;

                                foreach (var responce in indentDTO.Responces)
                                {
                                    if (responce.Executor.ExecutorId == clientId)
                                    {
                                        clientPossibilities.executorIsAllowToSendResponce = false;
                                    }
                                }
                            }
                        }
                    }
                }

                if (indentDTO.Executor != null)
                {
                    if (indentDTO.Executor.ExecutorId == clientId &&
                        (indentDTO.Recall == null || indentDTO.Recall.ExecutorMarkForCustomer == null))
                    {
                        clientPossibilities.executorIsAllowToWriteRecall = true;
                    }
                }
                return(clientPossibilities);
            }

            default: return(clientPossibilities);
            }
        }
示例#3
0
 public IndentFullViewModel()
 {
     indentViewModel     = new IndentViewModel();
     clientOpportunities = new HelpModelForClientOpportunities();
 }