public bool Remove(T item, OperationDetails od)
        {
            var operation = new Operation <T>(item, od);

            if (!Contains(item))
            {
                return(false);
            }

            if (Deletions.Add(operation))
            {
                _setRisk(od.Risk);
                return(true);
            }

            return(false);
        }
        //[ValidateAntiForgeryToken]
        public async Task <JsonResult> Register(RegisterModel model, int hotelId = 0)
        {
            await SetInitialDataAsync();

            if (ModelState.IsValid)
            {
                UserDTO userDto = new UserDTO
                {
                    Email           = model.Email,
                    Password        = model.Password,
                    Surname         = model.Surname,
                    Name            = model.Name,
                    TelephoneNumber = model.PhoneNumber
                };
                userDto.Role = hotelId != 0 ? "employee" : "user";
                OperationDetails operationDetails = await UserService.Create(userDto);

                if (operationDetails.Succedeed)
                {
                    if (hotelId != 0)
                    {
                        string userId = operationDetails.Message;
                        await EmployeeService.Create(new EmployeeDTO
                        {
                            ApplicationUserId = userId,
                            HotelId           = hotelId
                        });
                    }
                    var res = new JsonResult
                    {
                        Data = ""
                    };
                    return(res);
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }
            var result = new JsonResult
            {
                Data = "error"
            };

            return(result);
        }
Example #3
0
 public ActionResult Edit(EditUserViewModel model)
 {
     try
     {
         var user = GetUser();
         if (ModelState.IsValid)
         {
             OperationDetails operationDetails = userService.EditUser(user, model.OldPassword, model.NewPassword);
             ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
         }
     }
     catch (ValidationException ex)
     {
         ModelState.AddModelError(ex.Property, ex.Message);
     }
     return(View(model));
 }
Example #4
0
        public async Task <ActionResult> SaveVideo(VideoViewModel model)
        {
            string virtualSrcPath = "~/Videos/" + User.Identity.Name + "/temporary/videopath/" + model.FileName;
            string srcPath        = Server.MapPath(virtualSrcPath);

            if (System.IO.File.Exists(srcPath))
            {
                if (ModelState.IsValid)
                {
                    using (IVideoService videoService = ServiceCreator.CreateVideoService(Connection))
                    {
                        string virtualDestPath = "~/Content/Videos/" + User.Identity.Name + "/" + model.PlaylistId + "/";
                        string destPath        = Server.MapPath(virtualDestPath);
                        string hashedFileName  = model.FileName.GetHashCode() + DateTime.Now.Ticks + ".mp4";;
                        bool   isExists        = Directory.Exists(destPath);
                        if (!isExists)
                        {
                            Directory.CreateDirectory(destPath);
                        }
                        destPath += hashedFileName;
                        System.IO.File.Copy(srcPath, destPath);
                        System.IO.File.Delete(srcPath);

                        VideoDTO videoDto = new VideoDTO();
                        videoDto.Name        = model.Name;
                        videoDto.IsDeleted   = false;
                        videoDto.Description = model.Description;
                        videoDto.UserName    = User.Identity.Name;
                        videoDto.Path        = virtualDestPath.Substring(1) + hashedFileName;
                        videoDto.PlaylistId  = model.PlaylistId;
                        OperationDetails operationDetail = await videoService.AddVideo(videoDto);

                        return(RedirectToAction("PlaylistConcrete", "Playlist", new { playlistId = model.PlaylistId }));
                    }
                }
                else
                {
                    return(AddVideo(model));
                }
            }
            else
            {
                ModelState.AddModelError("FileNotFound", "Can't found your file. Please try to upload it again.");
                return(AddVideo(model));
            }
        }
Example #5
0
        public async Task <ActionResult> RemoveUserFromRole(string roleId, string userId, string returnUrl)
        {
            //todo id ==null
            string           currentUserId    = HttpContext.User.Identity.GetUserId();
            OperationDetails operationDetails = await _identityService.RemoveUserFromRole(currentUserId, userId, roleId);

            if (operationDetails.Succedeed)
            {
                TempData["message"] = operationDetails.Message;
                return(Redirect(string.IsNullOrWhiteSpace(returnUrl) ? Url.Action("Roles") : returnUrl));
            }
            else
            {
                TempData["message"] = operationDetails.Message;
                return(RedirectToAction("Roles"));
            }
        }
Example #6
0
        public async Task <OperationDetails> Update(UserDTO item)
        {
            OperationDetails resultOperation;
            ClientProfile    clientProfile = _mapper.Map <UserDTO, ClientProfile>(item);

            clientProfile = await _database.ProfileRepository.Update(clientProfile);

            if (clientProfile == null)
            {
                resultOperation = new OperationDetails(false, string.Empty, string.Empty);
            }
            else
            {
                resultOperation = new OperationDetails(true, string.Empty, string.Empty);
            }
            return(resultOperation);
        }
        public async Task <ActionResult> AddStoreType(StoreTypeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            StoreTypeDto     storeTypeDto     = mapper.Map <StoreTypeViewModel, StoreTypeDto>(model);
            OperationDetails operationDetails = await storeTypeService.AddStoreTypeAsync(storeTypeDto);

            if (operationDetails.Succedeed)
            {
                return(View("SuccessAdd"));
            }
            ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
            return(View(model));
        }
        public ActionResult AddEpisode(string id, int serialId, string count, string name, DateTime?date)
        {
            string message = "";

            try
            {
                var temp  = Convert.ToInt32(id);
                var temp2 = Convert.ToInt32(count);
                OperationDetails opDet = serialService.AddEpisode(temp, temp2, name, date);
                message = opDet.Message;
            }
            catch (ValidationException ex)
            {
                message = ex.Message;
            }
            return(RedirectToAction("SerialInfo", new { id = serialId, message }));
        }
Example #9
0
        public async Task <OperationDetails> DeleteItemAsync(TType id, OperationDetails MessageSuccess, OperationDetails MessageFail)
        {
            TEntity Item = await repository.FindByIdAsync(id);

            if (Item == null)
            {
                return(MessageFail);
            }
            else
            {
                await repository.DeleteAsync(id);

                await repository.SaveChangesAsync();

                return(MessageSuccess);
            }
        }
        // GET: Test/Subscribe
        public async Task <ActionResult> Subscribe(int?id)
        {
            try
            {
                // I. Checks.
                string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId();
                if (currentUserId == null)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                // Check id.
                if (!int.TryParse(id.ToString(), out int intId))
                {
                    return(RedirectToAction("Index"));
                }

                // II. Add a new subscription to DB.
                if (ModelState.IsValid)
                {
                    SubscriptionDTO subscriptionDTO = new SubscriptionDTO
                    {
                        UserProfileId      = currentUserId,
                        CourseId           = intId,
                        SubscriptionPeriod = 1,
                        IsApproved         = false
                    };
                    OperationDetails operationDetails = await SubscriptionService.CreateAsync(subscriptionDTO, currentUserId);

                    if (operationDetails.Succedeed)
                    {
                        return(PartialView("Report", operationDetails));
                    }
                    else
                    {
                        ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                        return(PartialView("Report", operationDetails));
                    }
                }
                ViewBag.Message = "Non valid";
                return(PartialView());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #11
0
        public async Task CreateUser_EmailNull_ShouldReturnFalseInOperationDetails()
        {
            //Arrange
            var         mock        = new Mock <IUnitOfWork>();
            UserService userService = new UserService(mock.Object);
            UserDTO     userDto     = new UserDTO()
            {
                Email = null, Id = "id", Password = "******", UserName = "******", Role = "User"
            };
            var expectedOpDet = new OperationDetails(false, "", "");

            //Act
            var actualOpDet = await userService.Create(userDto);

            //Assert
            Assert.AreEqual(expectedOpDet.Succeeded, actualOpDet.Succeeded, "True OperationDetails.Succeded result occurred");
        }
        public async Task <IActionResult> RegisterAsync([FromForm] RegisterUserBindingModel model)
        {
            var user = await _userService.GetUserAsync(model.UserName);

            if (user == null)
            {
                var creator = await _userService.GetUserAsync(User?.Identity?.Name);

                await _userService.CreateUserAsync(model.UserName, model.Password, model.Email, model.Role, creator);

                return(Ok(OperationDetails.Success($"User '@{model.UserName}' has been registered successfully.")));
            }
            else
            {
                return(BadRequest(OperationDetails.Error($"User '@{model.UserName}' already exists.")));
            }
        }
Example #13
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                UserDTO userDto = _mapper.Map <RegisterModel, UserDTO>(model);

                OperationDetails operationDetails = await _userService.CreateAsync(userDto);

                if (operationDetails.Succedeed)
                {
                    bool auth = await _userService.AuthenticateAsync(userDto);

                    return(RedirectToAction("Index", "Home"));
                }
                ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
            }
            return(View(model));
        }
 public ActionResult ToAdding(Serial serial)
 {
     try
     {
         if (ModelState.IsValid)
         {
             OperationDetails operationDetails = serialService.Adding(serial.Name, serial.Begin, serial.Picture, serial.Country
                                                                      , serial.Description, serial.Duration, serial.Status);
             ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
             return(RedirectToAction("Index", new { message = operationDetails.Message }));
         }
     }
     catch (ValidationException ex)
     {
         ModelState.AddModelError(ex.Property, ex.Message);
     }
     return(View(serial));
 }
        public async Task <IActionResult> SetAdStatus(int adId, int adStatus)
        {
            ModerationAdIndexViewModel model =
                new ModerationAdIndexViewModel {
                AdList = new List <AdDTO>()
            };

            OperationDetails <int> operationDetails = new OperationDetails <int>(false, "", 0);

            operationDetails = await _adService.SetStatusAd(adId, adStatus);

            if (!operationDetails.Succedeed)
            {
                return(View("Index", model.StatusMessage = operationDetails.Message));
            }

            return(RedirectToAction("Index", adStatus));
        }
        public async Task<ActionResult> Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            UserDto userDto = mapper.Map<RegisterModel, UserDto>(model);
            userDto.Role = UserRoles.User;

            OperationDetails operationDetails = await userService.AddUserAsync(userDto);
            if (operationDetails.Succedeed)
            {
                return View("SuccessRegister");
            }
            ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
            return View(model);
        }
Example #17
0
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            string oldPass     = model.OldPassword;
            string newPass     = model.NewPassword;
            string confirmPass = model.ConfirmPassword;

            if (newPass == confirmPass)
            {
                OperationDetails details = await _profileService.ChangePassword(AuthenticationManager.User.Identity.Name, oldPass, newPass);

                if (details.Succedeed)
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View(model));
        }
Example #18
0
        public async Task <ActionResult> DeletePost(BlogDto model, string url)
        {
            var currentUser = User.Identity.GetUserId();

            if (model.UserProfileId != currentUser)
            {
                return(RedirectToAction("Index", "Blog"));
            }

            OperationDetails operationDetails = await BlogService.DeletePost(model.Id);

            if (!operationDetails.Succedeed)
            {
                ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
            }

            return(RedirectToAction("Index", "Blog"));
        }
Example #19
0
        public IHttpActionResult EditUser(int id, UserDTO userDTO)
        {
            if (id != userDTO.Id)
            {
                return(BadRequest());
            }

            OperationDetails od = userService.EditUser(userDTO);

            if (od.Succeeded == false)
            {
                return(NotFound());
            }
            else
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
        }
        public async Task <ActionResult> _UpdateEmail(UpdateEmailModel model)
        {
            if (ModelState.IsValid)
            {
                OperationDetails result = await _userManagementService.UpdateUserEmail(UserId, model.Email);

                if (result.Succeeded)
                {
                    TempData["PartialMessage"] = result.Message;
                }
                else
                {
                    TempData["PartialMessage"] = result.Message;
                }
            }

            return(PartialView(model));
        }
Example #21
0
        public async Task <OperationDetails> UpdateItemAsync(TEntityDto ItemDto, TType idDto,
                                                             OperationDetails MessageSuccess, OperationDetails MessageFail)
        {
            TEntity ItemEntity = await repository.FindByIdAsync(idDto);

            if (ItemEntity != null)
            {
                ItemEntity = Map <TEntityDto, TEntity>(ItemDto);
                repository.Update(ItemEntity);
                await repository.SaveChangesAsync();

                return(MessageSuccess);
            }
            else
            {
                return(MessageFail);
            }
        }
Example #22
0
        public ActionResult Create(CreateOrderViewModel order, HttpPostedFileBase loadImage)
        {
            if (ModelState.IsValid)
            {
                PictureViewModelBLL picture = null;
                if (!ReferenceEquals(loadImage, null))
                {
                    byte[] image;
                    using (var binaryReader = new BinaryReader(loadImage.InputStream))
                    {
                        image = binaryReader.ReadBytes(loadImage.ContentLength);
                    }
                    picture = new PictureViewModelBLL {
                        Image = image
                    };
                    _pictureService.Create(image);
                    _unitOfWork.Save();
                }

                Mapper.Initialize(cfg => cfg.CreateMap <CreateOrderViewModel, OrderViewModelBLL>()
                                  .ForMember("CategoryId", opt => opt.MapFrom(c => _categoryService.FindByName(c.Category).Id))
                                  .ForMember("StatusId", opt => opt.MapFrom(c => 1))
                                  .ForMember("AdminStatus", opt => opt.MapFrom(c => false))
                                  .ForMember("UploadDate", opt => opt.MapFrom(c => DateTime.Now))
                                  .ForMember("UserId", opt => opt.MapFrom(c => User.Identity.GetUserId <int>()))
                                  .ForMember("PictureId", opt => opt.MapFrom(c => _pictureService.FindByBytes(picture.Image).Value))
                                  );
                OrderViewModelBLL orderDto = Mapper.Map <CreateOrderViewModel, OrderViewModelBLL>(order);

                OperationDetails operationDetails = _orderService.Create(orderDto);
                _unitOfWork.Save();
                if (operationDetails.Succedeed)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
            }

            ModelState.AddModelError("", "Creation error");
            ViewBag.Category    = new SelectList(_categoryService.GetAll(), "Name", "Name");
            ViewBag.DefaultPath =
                $"data: image/png; base64, {Convert.ToBase64String(System.IO.File.ReadAllBytes(Server.MapPath(DefaultImageName)))}";
            return(View(order));
        }
        public async Task <OperationDetails <int> > SaveAd(
            string userName,
            AdDTO ad,
            IFormFileCollection productPhotos)
        {
            OperationDetails <int> operationDetails = new OperationDetails <int>(false, "", 0);
            ApplicationUser        user             = new ApplicationUser();

            if (ad == null)
            {
                return(new OperationDetails <int>(false, "new Ad can't be null or empty", 0));
            }

            if (String.IsNullOrEmpty(userName))
            {
                return(operationDetails);
            }

            user = await _uof.UserRepository.FindUserByUserName(userName);

            if (user == null)
            {
                return(operationDetails);
            }

            var newAd = _dataService.TransformingAdDTOToAdEntities(ad);

            newAd.ApplicationUser = user;

            if (newAd.AdId == 0)
            {
                newAd.AdStatusId = (int)AdStatuses.Activated;
                newAd.IsModerate = true;
                operationDetails = await CreateAd(user, newAd, productPhotos);
            }
            else
            {
                newAd.AdStatusId = (int)AdStatuses.InProgress;
                newAd.IsModerate = false;
                operationDetails = await UpdateAd(user, newAd, productPhotos);
            }

            return(operationDetails);
        }
        public ActionResult Send(CreateCommentViewModel comment)
        {
            if (!User.IsInRole("user"))
            {
                throw new Exception("User is not authorized");
            }

            bool commentIsEmpty = comment.Text == null || comment.Text.Equals(string.Empty);

            Mapper.Initialize(cfg => cfg.CreateMap <CreateCommentViewModel, CommentViewModelBLL>()
                              .ForMember("Date", opt => opt.MapFrom(c => DateTime.Now))
                              .ForMember("CustomerId", opt => opt.MapFrom(c => User.Identity.GetUserId <int>()))
                              .ForMember("Rating", opt => opt.MapFrom(c => c.Rating.ToCharArray().Where(r => r == '★').Count()))
                              );
            CommentViewModelBLL commentDto = Mapper.Map <CreateCommentViewModel, CommentViewModelBLL>(comment);

            if (ModelState.IsValid)
            {
                OperationDetails operationDetails = _commentService.Create(commentDto);
                _unitOfWork.Save();
                if (!operationDetails.Succedeed)
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }

                var user = _userService.FindById(comment.PerformerId);
                if (user.CommentsBll != null)
                {
                    user.Rating = (int)Math.Round((float)(user.CommentsBll.Select(c => c.Rating).Sum() / user.CommentsBll.Count));
                }
                operationDetails = _userService.Update(user);
                _unitOfWork.Save();
                if (!operationDetails.Succedeed)
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }
            else
            {
                throw new Exception("Model is not valid");
            }

            return(RedirectToAction("Details", "Performers", new { id = comment.PerformerId, emptyComment = commentIsEmpty }));
        }
        // Get test results.
        public async Task <ActionResult> GetCurrentTestResults(int?id)
        {
            try
            {
                // I. Clear controller properties for processing a test period.
                TestPeriod    = 0;
                StartTestTime = null;

                // II. Check.
                if (AllAnswers.Count == 0 || UserAnswers.Count == 0)
                {
                    return(RedirectToAction("Index"));
                }

                // III.Get the test result.
                OperationDetails operationDetails = PLRepository.CalculateTestResults(AllAnswers, UserAnswers, TestQuetions, out TestResultViewModel testResult);
                if (!operationDetails.Succedeed)
                {
                    return(View("Report", operationDetails));
                }
                // Is the test passed?
                int       firstQuestionId = AllAnswers.FirstOrDefault().Key;
                CourseDTO courseDTO       = (await QuestionService.GetAsync(firstQuestionId)).Topic.Course;
                testResult.IsPassedTest = testResult.Result > testResult.MaxScore * courseDTO.PassingScore / 100;
                // Set ViewBag property for a View.
                ViewBag.CourseName = courseDTO.CourseTitle;

                // IV.Set testResult properies (Result, MaxScore and TestResultDetails).
                testResult.Result   = testResult.Result * 1000 / testResult.MaxScore;
                testResult.MaxScore = 1000;
                foreach (var item in testResult.TestResultDetails)
                {
                    item.Topic    = (await QuestionService.GetAsync(item.QuestionId)).Topic.TopicTitle;
                    item.Question = (await QuestionService.GetAsync(item.QuestionId)).QuestionText;
                }

                // V.
                return(View(testResult));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        // ModeratorSuscription/TrialSubscribe
        public async Task <ActionResult> TrialSubscribe()
        {
            try
            {
                //I. Check.
                string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId();
                if (currentUserId == null)
                {
                    return(new HttpUnauthorizedResult());
                }

                // II. Create a trial moderator subscription.
                if (ModelState.IsValid)
                {
                    SubscriptionForModeratorDTO subscriptionDTO = new SubscriptionForModeratorDTO
                    {
                        UserProfileId      = currentUserId,
                        CourseCount        = 1,
                        SubscriptionPeriod = 7,
                        IsTrial            = true,
                        IsApproved         = true
                    };
                    OperationDetails operationDetails = await SubscriptionForModeratorService.CreateAsync(subscriptionDTO, currentUserId);

                    if (operationDetails.Succedeed)
                    {
                        return(PartialView("Report", operationDetails));
                    }
                    else
                    {
                        ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                        return(PartialView("Report", operationDetails));
                    }
                }

                // III.
                ViewBag.Message = "Non valid";
                return(PartialView());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #27
0
        public IHttpActionResult DeleteUser(int id)
        {
            UserDTO user = userService.FindUser(id);

            if (user == null)
            {
                return(NotFound());
            }
            OperationDetails od = userService.DeleteUser(id);

            if (od.Succeeded == false)
            {
                return(BadRequest());
            }
            else
            {
                return(Ok(user));
            }
        }
Example #28
0
        public void WrongUserCreationTest(UserDTO userDto)
        {
            //Arrange
            var user = new ApplicationUser
            {
                Email = "ok",
                Roles = { new IdentityUserRole {
                              UserId = "test", RoleId = "test"
                          } },
                ClientProfile = new ClientProfile {
                    Name = "test"
                }
            };

            var mockStore = new Mock <IUserStore <ApplicationUser> >();

            mockStore.Setup(x => x.FindByIdAsync(It.IsAny <string>())).Returns(Task.FromResult(user));
            mockStore.As <IUserEmailStore <ApplicationUser> >().Setup(x => x.FindByEmailAsync("existed")).Returns(Task.FromResult((ApplicationUser)null));
            mockStore.As <IUserPasswordStore <ApplicationUser> >();
            mockStore.As <IUserRoleStore <ApplicationUser> >().Setup(x => x.AddToRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .Returns(Task.FromResult(IdentityResult.Success));
            mockStore.As <IUserRoleStore <ApplicationUser> >().Setup(x => x.GetRolesAsync(It.IsAny <ApplicationUser>()))
            .Returns(Task.FromResult((IList <string>) new List <string>()));
            mockStore.Setup(x => x.CreateAsync(It.IsAny <ApplicationUser>()))
            .Returns(Task.FromResult(IdentityResult.Success));

            var mockDbSet = new Mock <DbSet <ClientProfile> >(MockBehavior.Strict);

            mockDbSet.Setup(x => x.Add(It.IsAny <ClientProfile>())).Returns(new ClientProfile());

            var userManager = new ApplicationUserManager(mockStore.Object);

            var mock = new Mock <IUnitOfWork>();

            mock.Setup(a => a.UserManager).Returns(userManager);

            //Act
            var userService         = new UserService(mock.Object);
            OperationDetails result = userService.Create(userDto);

            //Assert
            Assert.That(result.Succedeed, Is.False);
        }
        public async Task <ActionResult> Registration(RegistrationViewModel model)
        {
            await SetInitialDataAsync();

            if (ModelState.IsValid)
            {
                UserDTO userDto = new UserDTO
                {
                    Email    = model.Email,
                    Password = model.Password,
                    Address  = model.Address,
                    Name     = model.Name,
                    Role     = "user"
                };
                OperationDetails operationDetails = await UserService.CreateAsync(userDto);

                if (operationDetails.Succedeed)
                {
                    UserDTO userDtoWithId = await UserService.FindAsync(userDto.Email, userDto.Password);

                    string code = await UserService.GenerateEmailConfirmationTokenAsync(userDtoWithId.Id);

                    string callBackURL = Url.Action("ConfirmEmail", "Account", new { userId = userDtoWithId.Id, code = code },
                                                    protocol: Request.Url.Scheme);

                    StringBuilder confirmingMessage = new StringBuilder(ConfigurationManager.AppSettings["EmailConfirmingMessageStart"]);
                    confirmingMessage.Append("<a href=\"");
                    confirmingMessage.Append(callBackURL);
                    confirmingMessage.Append("\">Press to confirm email. <a/>");
                    confirmingMessage.Append(ConfigurationManager.AppSettings["EmailConfirmingMessageEnd"]);

                    string subject = ConfigurationManager.AppSettings["Subject"];
                    await UserService.SendEmailAsync(userDtoWithId.Id, subject, confirmingMessage.ToString());

                    return(View("DisplayEmail"));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }
            return(View(model));
        }
        public async Task <OperationDetails <IQueryable <PurchaseDTO> > > GetPurchaseByUserId(string userId)
        {
            OperationDetails <IQueryable <PurchaseDTO> > operationDetails =
                new OperationDetails <IQueryable <PurchaseDTO> > (false, "Что-то пошло не так, проверте данные и повториет позже", null);

            if (string.IsNullOrEmpty(userId))
            {
                return(operationDetails);
            }

            var user = await _uof.UserRepository.FindByIdAsync(userId);

            if (user == null)
            {
                return(operationDetails);
            }

            var ads = await _uof.AdRepository.FindAdsByUserId(userId);

            if (ads == null)
            {
                return(operationDetails);
            }

            var purchasesDTO = ads.SelectMany(x => x.Purhcases.Select(
                                                  p => new PurchaseDTO
            {
                PurchaseId          = p.PurchaseId,
                TotalCost           = p.TotalCost,
                DateOfPayment       = p.DateOfPayment,
                StartDateService    = p.StartDateService,
                EndDateService      = p.EndDateService,
                IsPayed             = p.IsPayed,
                IsActive            = p.IsActive,
                ServicesId          = p.ServicesId,
                ServiceActiveTimeId = p.ServiceActiveTimeId,
                AdId = p.AdId
            })).AsQueryable();

            operationDetails = new OperationDetails <IQueryable <PurchaseDTO> >(true, "", purchasesDTO);

            return(operationDetails);
        }