Ejemplo n.º 1
0
        private void ValidateProfileCollections(ProfileModel profileModel, Profile model)
        {

            var llp = new LookupListProcessor<ProfileModel, Profile, CountriesToVisitModel, CountriesToVisit, string>(
                p => p.CountriesToVisit,
                p => p.CountriesToVisit,
                p => (string)p.Country,
                p => p.Country,
                (modelData, country) => _profileService.DeleteCountriesToVisit(modelData.Id, country),
                (modelData, country) => _profileService.AddCountriesToVisit(modelData.Id, country)
                );

            var llp2 = new LookupListProcessor<ProfileModel, Profile, LanguagesSpokenModel, LanguagesSpoken, string>(
                p => p.LanguagesSpoken,
                p => p.LanguagesSpoken,
                p => (string)p.Language,
                p => p.Language,
                (modelData, language) => _profileService.DeleteLanguagesSpoken(modelData.Id, language),
                (modelData, language) => _profileService.AddLanguagesSpoken(modelData.Id, language)
                );

            var llp3 = new LookupListProcessor<ProfileModel, Profile, SearchingForModel, SearchingFor, LookingFor>(
                p => p.Searches,
                p => p.Searches,
                p => (LookingFor)p.Search,
                p => p.Search,
                (modelData, search) => _profileService.DeleteSearches(modelData.Id, search),
                (modelData, search) => _profileService.AddSearches(modelData.Id, search)
                );

            llp.Process(Request, ModelState, profileModel, model);
            llp2.Process(Request, ModelState, profileModel, model);
            llp3.Process(Request, ModelState, profileModel, model);
        }
Ejemplo n.º 2
0
        public ActionResult Create(string key, ProfileModel model)
        {
            if (KatushaUser.Gender > 0) throw new KatushaNotAllowedException(KatushaProfile, KatushaUser, "CREATE GET");
            try {
                if (!ModelState.IsValid) return View(model);
                var genderValue = key.ToLowerInvariant();
                switch (genderValue) {
                    case "girl":
                        model.Gender = Sex.Female;
                        break;
                    case "man":
                        model.Gender = Sex.Male;
                        break;
                    default:
                        throw new KatushaGenderNotExistsException(null);
                }
                var profile = Mapper.Map<Profile>(model);
                profile.UserId = KatushaUser.Id;
                profile.Guid = KatushaUser.Guid;
                if (!ModelState.IsValid) return View(model);

                _profileService.CreateProfile(profile);
                //ValidateProfileCollections(model, profile);                
                KatushaProfile = profile; // _profileService.GetProfileDB(profile.Id, p => p.CountriesToVisit, p => p.LanguagesSpoken, p => p.Searches);
                //ValidateProfileCollections(model, KatushaProfile);
                if (!ModelState.IsValid) return View(key, model);
                return RedirectToAction("Show", new { key = (String.IsNullOrWhiteSpace(profile.FriendlyName)) ? profile.Guid.ToString() : profile.FriendlyName });
            } catch (KatushaFriendlyNameExistsException) {
                ModelState.AddModelError("FriendlyName", ResourceService.ResourceValue("FriendlyNameExists"));
                return View(model);
            } catch (KatushaException) {
                throw;
            } catch (Exception ex) {
                ModelState.AddModelError("Model", ex);
                return View(model);
            }
        }
Ejemplo n.º 3
0
 public ActionResult Edit(ProfileModel model)
 {
     try {
         ViewBag.SameProfile = true;
         var profileModel = KatushaProfile;
         if (!ModelState.IsValid) return View(model);
         var profile = Mapper.Map<Profile>(model);
         profile.Id = profileModel.Id;
         profile.Guid = profileModel.Guid;
         profile.Gender = profileModel.Gender;
         profile.ProfilePhotoGuid = profileModel.ProfilePhotoGuid;
         ValidateProfileCollections(model, profileModel);
         if (!ModelState.IsValid) return View(model);
         _profileService.UpdateProfile(profile);
         return RedirectToAction("Show", new { key = (String.IsNullOrWhiteSpace(profile.FriendlyName)) ? profile.Guid.ToString() : profile.FriendlyName });
     } catch (KatushaFriendlyNameExistsException) {
         ModelState.AddModelError("FriendlyName", ResourceService.ResourceValue("FriendlyNameExists"));
         return View(model);
     } catch (KatushaException) {
         throw;
     } catch {
         return View();
     }
 }
Ejemplo n.º 4
0
 public ActionResult Create(string key)
 {
     if (KatushaUser.Gender > 0) {
         if(KatushaUser.Guid != Guid.Empty) {
             var id = ProfileService.GetProfileId(KatushaUser.Guid);
             if(id > 0) { // profile exists
                 return RedirectToAction("Show", new {key = KatushaUser.Guid});
             }
         } else {
             throw new KatushaNotAllowedException(KatushaProfile, KatushaUser, "CREATE GET");
         }
     }
     var model = new ProfileModel();
     if(key == null)
         throw new KatushaGenderNotExistsException(null);
     var genderValue = key.ToLowerInvariant();
     switch (genderValue) {
         case "girl":
             model.Gender = Sex.Female;
             break;
         case "man":
             model.Gender =  Sex.Male;
             break;
         default:
             throw new KatushaGenderNotExistsException(null);
     }
     return View(model);
 }