示例#1
0
        public async Task <IActionResult> SetProfile([Bind("UserId,ProfilePicture,GivenName,FamilyName,CompanyName,SelectedTags")] AdvertiserProfileViewModel advertiserProfileViewModel)
        {
            if (ModelState.IsValid)
            {
                User    user = _context.Users.Where(u => u.UserId == advertiserProfileViewModel.UserId).FirstOrDefault();
                var     profilePictureUri = new ProfilePictureController().Upload(advertiserProfileViewModel.ProfilePicture, DateTime.Now.ToFileTime() + "-" + advertiserProfileViewModel.GivenName + "-" + advertiserProfileViewModel.FamilyName + "-ProfilePicture");
                Profile userProfile       = new AdvertiserProfile
                {
                    User           = user,
                    GivenName      = advertiserProfileViewModel.GivenName,
                    FamilyName     = advertiserProfileViewModel.FamilyName,
                    CompanyName    = advertiserProfileViewModel.CompanyName,
                    ProfilePicture = profilePictureUri.Result
                };
                _context.Add(userProfile);
                await _context.SaveChangesAsync();

                var selectedTags   = _context.Tags.Where(t => advertiserProfileViewModel.SelectedTags.Contains(t.TagId.ToString())).ToList();
                var advertiserTags = selectedTags.Select(st => new AdvertiserProfileTag {
                    AdvertiserProfile = userProfile as AdvertiserProfile, Tag = st
                }).ToList();
                _context.AddRange(advertiserTags.ToArray());
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(advertiserProfileViewModel));
        }
示例#2
0
        public async Task <IActionResult> SetProfile([Bind("UserId,GivenName,FamilyName,ProfilePicture")] PublisherProfileViewModel publisherProfileViewModel)
        {
            if (ModelState.IsValid)
            {
                User    user = _context.Users.Where(u => u.UserId == publisherProfileViewModel.UserId).FirstOrDefault();
                var     profilePictureUri = new ProfilePictureController().Upload(publisherProfileViewModel.ProfilePicture, DateTime.Now.ToFileTime() + "-" + publisherProfileViewModel.GivenName + "-" + publisherProfileViewModel.FamilyName + "-ProfilePicture");
                Profile userProfile       = new PublisherProfile
                {
                    User           = user,
                    GivenName      = publisherProfileViewModel.GivenName,
                    FamilyName     = publisherProfileViewModel.FamilyName,
                    ProfilePicture = profilePictureUri.Result
                };
                _context.Add(userProfile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(publisherProfileViewModel));
        }
示例#3
0
 public IActionResult EditProfile([Bind("ProfileId,NewProfilePicture,GivenName,FamilyName,CompanyName,Password,ConfirmPassword,SelectedTags")] AdvertiserEditProfileViewModel advertiserEditProfileViewModel)
 {
     advertiserEditProfileViewModel.ProfilePicture = _context.AdvertiserProfiles
                                                     .Where(ap => ap.ProfileId == advertiserEditProfileViewModel.ProfileId)
                                                     .FirstOrDefault()
                                                     .ProfilePicture;
     if (ModelState.IsValid)
     {
         AdvertiserProfile advertiserProfile = _context.AdvertiserProfiles.Include(ap => ap.User).Where(ap => ap.ProfileId == advertiserEditProfileViewModel.ProfileId).FirstOrDefault();
         advertiserProfile.GivenName     = advertiserEditProfileViewModel.GivenName;
         advertiserProfile.FamilyName    = advertiserEditProfileViewModel.FamilyName;
         advertiserProfile.CompanyName   = advertiserEditProfileViewModel.CompanyName;
         advertiserProfile.User.Password = advertiserEditProfileViewModel.Password;
         if (advertiserEditProfileViewModel.NewProfilePicture != null)
         {
             var profilePictureUri = new ProfilePictureController()
                                     .Upload(
                 advertiserEditProfileViewModel.NewProfilePicture,
                 DateTime.Now.ToFileTime() + "-" + advertiserEditProfileViewModel.GivenName + "-" + advertiserEditProfileViewModel.FamilyName + "-ProfilePicture");
             advertiserProfile.ProfilePicture = profilePictureUri.Result;
         }
         _context.Update(advertiserProfile);
         _context.SaveChanges();
         string fileName = advertiserEditProfileViewModel.ProfilePicture.Split('/').Last();
         new ProfilePictureController().DeleteProfilePicture(fileName);
         return(RedirectToAction(nameof(Index)));
     }
     advertiserEditProfileViewModel.Tags = _context.Tags
                                           .Select(t => new SelectListItem
     {
         Text     = t.TypeName,
         Value    = t.TagId.ToString(),
         Selected = advertiserEditProfileViewModel.SelectedTags
                    .Where(st => int.Parse(st) == t.TagId)
                    .FirstOrDefault() != null
     })
                                           .ToList();
     return(View(advertiserEditProfileViewModel));
 }