Beispiel #1
0
        ///<summary>
        ///Returns view of executor profile which contains: recalls, indents with responces, personal data.
        ///Uses _PrivateOfficeExecutorLayout
        ///</summary>
        public ActionResult PrivateOffice()
        {
            var clientId = Session["Id"];

            if (clientId == null)
            {
                return(RedirectToAction("Registration", "Executor"));
            }

            int         executorId  = Convert.ToInt32(clientId);
            ExecutorDTO executorDTO = null;

            string cacheKey = "show-executor-" + executorId.ToString();

            executorDTO = HttpContext.Cache[cacheKey] as ExecutorDTO;

            if (executorDTO == null)
            {
                try
                {
                    executorDTO = _executorService.GetExecutorProfile(executorId);
                }
                catch (ValidationException e)
                {
                    return(RedirectToAction("Registration", "Executor"));
                }

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

            UserProfileViewModel userProfileView = _mapper.Map <UserProfileViewModel>(executorDTO);

            return(View(userProfileView));
        }
        public void ModificateProfileTest()
        {
            //Arrange
            int         fakeId           = 0;
            ExecutorDTO fakeExecutorDTO  = new ExecutorDTO();
            var         iExecutorService = new Mock <IExecutorService>();

            iExecutorService.Setup(x => x.GetExecutorPropertiesForEdition(fakeId)).Returns(fakeExecutorDTO);

            var iUserActivityService = new Mock <IUserActivityService>();

            ExecutorPropertiesForEditionViewModel fakeViewModel = new ExecutorPropertiesForEditionViewModel();
            var mapper = new Mock <IMapper>();

            mapper.Setup(x => x.Map <ExecutorPropertiesForEditionViewModel>(It.IsAny <ExecutorDTO>())).Returns(fakeViewModel);

            var controllerContext = new Mock <ControllerContext>();
            var controllerSession = new Mock <HttpSessionStateBase>();

            controllerContext.Setup(p => p.HttpContext.Session).Returns(controllerSession.Object);
            controllerContext.Setup(p => p.HttpContext.Session["Id"]).Returns(fakeId);

            ExecutorController executorControllerTest = new ExecutorController(iExecutorService.Object,
                                                                               iUserActivityService.Object, mapper.Object);

            executorControllerTest.ControllerContext = controllerContext.Object;

            //Act
            ViewResult view = executorControllerTest.ModificateProfile() as ViewResult;

            //Asert
            Assert.IsNotNull(view);
            Assert.IsNotNull(view.Model);
        }
        public ExecutorDTO GetExecutorPropertiesForEdition(int id)
        {
            Executor executor = _database.Executors.GetById(id);

            ExecutorDTO executorPropertiesForEdition = _mapper.Map <ExecutorDTO>(executor);

            return(executorPropertiesForEdition);
        }
Beispiel #4
0
        public async Task <ActionResult> SaveCustomerRecallForExecutor(UserActivityViewModel activityModel)
        {
            var clientId = Session["Id"];

            if (clientId == null)
            {
                return(RedirectToAction("Registration", "Customer"));
            }

            if (activityModel.Mark == null)
            {
                TempData["ErrorMessage"] = "Вы не оценили работу исполнителя!";

                return(RedirectToAction("ShowIndent", "Indent", new { id = activityModel.IndentId }));
            }

            int    customerId   = Convert.ToInt32(clientId);
            string customerName = Session["Name"].ToString();

            RecallDTO recallDTO = new RecallDTO()
            {
                RecallId = activityModel.IndentId,
                CustomerCommentForExecutor = activityModel.Comment,
                CustomerMarkForExecutor    = activityModel.Mark
            };

            await _userActivityService.SaveCustomerRecallForExecutor(recallDTO);

            string    cacheKeyForIndent = "show-indent-" + activityModel.IndentId.ToString();
            IndentDTO cachedIndent      = HttpContext.Cache[cacheKeyForIndent] as IndentDTO;

            if (cachedIndent != null)
            {
                HttpContext.Cache.Remove(cacheKeyForIndent);
            }
            string      cacheKeyForExecutor = "show-executor-" + activityModel.UserOpponentId.ToString();
            ExecutorDTO cachedExecutor      = HttpContext.Cache[cacheKeyForExecutor] as ExecutorDTO;

            if (cachedExecutor != null)
            {
                HttpContext.Cache.Remove(cacheKeyForExecutor);
            }

            NotificationDTO notificationDTO = GenerateNotification(activityModel, Role.Executor, "Recall");

            notificationDTO.FromId   = customerId;
            notificationDTO.FromName = customerName;

            await _userActivityService.SaveNotification(notificationDTO);

            return(RedirectToAction("ShowIndent", "Indent", new { id = activityModel.IndentId }));
        }
        public ExecutorDTO GetExecutorProfile(int id)
        {
            Executor executor = _database.Executors.GetProfile(id);

            if (executor == null)
            {
                throw new ValidationException("Были введены некорректные данные, попробуйте снова!", "");
            }

            ExecutorDTO executorDTO = _mapper.Map <ExecutorDTO>(executor);

            return(executorDTO);
        }
        public async Task SaveExecutorPropertiesAfterEdition(ExecutorDTO properties)
        {
            List <int?> categoriesValue = null;

            if (properties.Categories != null)
            {
                categoriesValue = new List <int?>();
                foreach (Category category in properties.Categories)
                {
                    categoriesValue.Add((int)category);
                }
            }

            await _database.Executors.SaveExecutorPropertiesAfterEdition(properties.Information, properties.ImgSrc,
                                                                         categoriesValue, properties.ExecutorId);
        }
Beispiel #7
0
        ///<summary>
        ///Allows executor to modificate profile: change 2 categories (once), download photo, change description.
        ///</summary>
        public ActionResult ModificateProfile()
        {
            if (TempData["ErrorMessage"] != null)
            {
                ViewBag.ErrorMessage = TempData["ErrorMessage"];
            }

            var clientId = Session["Id"];

            if (clientId == null)
            {
                return(RedirectToAction("Registration", "Executor"));
            }

            int executorId = Convert.ToInt32(clientId);

            ExecutorDTO executorDTO = _executorService.GetExecutorPropertiesForEdition(executorId);

            ExecutorPropertiesForEditionViewModel propertiesViewModel = _mapper.Map <ExecutorPropertiesForEditionViewModel>(executorDTO);

            return(View(propertiesViewModel));
        }
        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);
            }
        }
Beispiel #9
0
        public ActionResult ShowExecutor(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("ShowExecutorsPerPage", "Executor"));
            }

            int         executorId  = Convert.ToInt32(id);
            ExecutorDTO executorDTO = null;

            string cacheKey = "show-executor-" + executorId.ToString();

            executorDTO = HttpContext.Cache[cacheKey] as ExecutorDTO;

            if (executorDTO == null)
            {
                try
                {
                    executorDTO = _executorService.GetExecutorProfile(executorId);
                }
                catch (ValidationException e)
                {
                    return(new HttpStatusCodeResult(404));
                }

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

            if (TempData["OfferIndentToExecutorErrorMessage"] != null)
            {
                ViewBag.OfferIndentToExecutorErrorMessage = TempData["OfferIndentToExecutorErrorMessage"];
            }

            UserProfileViewModel userProfileView = _mapper.Map <UserProfileViewModel>(executorDTO);

            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);
            }

            if (clientId != null && (clientRole != null && clientRole == Role.Customer))
            {
                DefineIfCustomerCanSeePersonalExecutorData(ref userProfileView, clientId);
            }

            return(View(userProfileView));
        }
Beispiel #10
0
        public async Task <ActionResult> ModificateProfile(string information, string categoryFirst, string categorySecond)
        {
            var clientId = Session["Id"];

            if (clientId == null)
            {
                return(RedirectToAction("Registration", "Executor"));
            }

            int executorId = Convert.ToInt32(clientId);

            HashSet <Category> categories = null;

            if (categoryFirst != null && categorySecond != null)
            {
                if (categoryFirst.Equals(categorySecond))
                {
                    TempData["ErrorMessage"] = "Категории должны различаться!";

                    return(RedirectToAction("ModificateProfile", "Executor"));
                }
                else
                {
                    if (Session["Language"] != null)
                    {
                        string lan = Session["Language"].ToString();
                        IEnumerable <Category> categoriesInEnumEquivalent = new List <Category>();

                        if (lan == "en")
                        {
                            categoriesInEnumEquivalent = CategoryExtension.
                                                         TranslateFromEnglishToEnumEquivalents(new string[] { categoryFirst, categorySecond });
                        }
                        else
                        {
                            categoriesInEnumEquivalent = CategoryExtension.
                                                         TranslateFromRussianToEnumEquivalents(new string[] { categoryFirst, categorySecond });
                        }

                        categories = new HashSet <Category>(categoriesInEnumEquivalent);
                    }
                }
            }

            string imgSrc       = null;
            string fileMimeType = null;

            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase file = Request.Files[0];

                fileMimeType = file.ContentType;

                if (!fileMimeType.Equals("application/octet-stream"))
                {
                    if (fileMimeType.Equals("image/jpeg"))
                    {
                        imgSrc = Path.Combine(Server.MapPath("~/Content/Executor"), executorId.ToString() + ".jpeg");
                        if (System.IO.File.Exists(imgSrc))
                        {
                            System.IO.File.Delete(imgSrc);
                        }
                        file.SaveAs(imgSrc);
                    }
                    else
                    {
                        TempData["ErrorMessage"] = "Загружать фотографии разрешается только в jpeg формате!";

                        return(RedirectToAction("ModificateProfile", "Executor"));
                    }
                }
            }

            ExecutorDTO propertiesAfterEdition = new ExecutorDTO()
            {
                ExecutorId  = executorId,
                ImgSrc      = imgSrc,
                Information = information,
                Categories  = categories
            };

            await _executorService.SaveExecutorPropertiesAfterEdition(propertiesAfterEdition);

            string      cacheKeyForExecutor = "show-executor-" + executorId.ToString();
            ExecutorDTO cachedExecutor      = HttpContext.Cache[cacheKeyForExecutor] as ExecutorDTO;

            if (cachedExecutor != null)
            {
                HttpContext.Cache.Remove(cacheKeyForExecutor);
            }

            return(RedirectToAction("PrivateOffice", "Executor"));
        }