예제 #1
0
        public async Task <IActionResult> CreatePackage(TourPackage tourPackage)
        {
            if (ModelState.IsValid)
            {
                tourPackage.Id           = Guid.NewGuid();
                tourPackage.PackageCode  = GeneralUtilityMethods.GeneratePackageCode();
                tourPackage.Availability = AvailabilityStatus.Available.ToString();
                var Spots = tourPackage.Spots;
                tourPackage.Spots = null; // creates PK_Spot conflict otherwise

                // Create the tourPackage first.
                await _companyService.CreateTourPackage(tourPackage);

                // Add the spots
                foreach (var spot in Spots)
                {
                    spot.TourPackage   = null; // Create PK_Company conflict otherwise
                    spot.TourPackageId = tourPackage.Id;
                    await _tourPackageService.AddSpot(spot);
                }

                return(RedirectToAction("CompanyPublicView", "Company", new { companyId = tourPackage.CompanyId }));
            }

            return(View(tourPackage));
        }
예제 #2
0
        public async Task <IActionResult> EditProfile(RegistrationFormModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email); // returns ApplicationUser

                string imagePath  = _pathService.PictureFolder;
                string uploadPath = _webHostEnvironment.WebRootPath + imagePath;
                string demoImage  = _pathService.DummyUserImageUrl;

                if (user != null)
                {
                    user.IsVarified  = true;
                    user.FullName    = model.Name;
                    user.Email       = model.Email;
                    user.PhoneNumber = model.Mobile;
                    user.Address     = model.Address;
                    if (model.ImageFile != null && model.ImageFile.Length > 0)
                    {
                        user.ImageUrl = await GeneralUtilityMethods.GetSavedImageUrlAsync(model.ImageFile, uploadPath, demoImage);
                    }
                    var result = await _userManager.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Profile", "Account", new { userId = user.Id.ToString() }));
                    }
                }
            }

            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> EditCompany(EditCompanyViewModel model)
        {
            if (ModelState.IsValid)
            {
                string imagePath          = _pathService.PictureFolder;
                string physicalUploadPath = _webHostEnvironment.WebRootPath + imagePath;
                string demoImage          = _pathService.DummyCompanyImageUrl;
                model.Company.CompanyImageUrl = await GeneralUtilityMethods.GetSavedImageUrlAsync(model.ImageFile, physicalUploadPath, demoImage);

                imagePath                 = _pathService.LogoFolder;
                physicalUploadPath        = _webHostEnvironment.WebRootPath + imagePath;
                demoImage                 = _pathService.DummyCompanyLogo;
                model.Company.CompanyLogo = await GeneralUtilityMethods.GetSavedImageUrlAsync(model.LogoFile, physicalUploadPath, demoImage);

                await _companyService.EditAsync(model.Company);

                return(RedirectToAction("CompanyPublicView", "Company", new { companyId = model.Company.Id.ToString() }));
            }

            return(View(model));
        }
예제 #4
0
 private PostViewModel PreparePostViewModel(Post post, ApplicationUser loggedInUser)
 {
     return(new PostViewModel
     {
         PostId = post.Id,
         AuthorId = post.AuthorId,
         AuthorName = post.AuthorName,
         AuthorImageUrl = $"{_pathService.PictureFolder}{post.AuthorImageUrl}",
         CreationDate = GeneralUtilityMethods.GetFormattedDate(post.CreationDate),
         Message = post.Message,
         Likes = post.Likes.Count,
         IsLikedBy = post.Likes.Where(l => l.AuthorId == loggedInUser.Id).Any(),
         IsPostAuthor = post.AuthorId == loggedInUser.Id,
         Comments = post.Comments.Select(cmt => new CommentViewModel
         {
             CommentId = cmt.Id,
             PostId = cmt.PostId,
             AuthorId = cmt.AuthorId,
             AuthorName = cmt.AuthorName,
             AuthorImageUrl = $"{_pathService.PictureFolder}{cmt.AuthorImageUrl}",
             CreationDate = GeneralUtilityMethods.GetFormattedDate(cmt.CreationDate),
             Message = cmt.Message,
             IsCommentAuthor = cmt.AuthorId == loggedInUser.Id,
             Replays = cmt.Replays.Select(rpl => new ReplayViewModel
             {
                 ReplayId = rpl.Id,
                 CommentId = rpl.CommentId,
                 AuthorId = rpl.AuthorId,
                 AuthorName = rpl.AuthorName,
                 AuthorImageUrl = $"{_pathService.PictureFolder}{rpl.AuthorImageUrl}",
                 CreationDate = GeneralUtilityMethods.GetFormattedDate(rpl.CreationDate),
                 Message = rpl.Message,
                 IsReplayAuthor = rpl.AuthorId == loggedInUser.Id
             }).ToList()
         }).ToList()
     });
 }