public static Models.VM.TravelerProfileVM LoadTravelerVM(TravelerProfile tp)
        {
            Models.VM.TravelerProfileVM profileVM = new Models.VM.TravelerProfileVM(tp);


            return(profileVM);
        }
        public async Task <ActionResult> Edit()
        {
            try
            {
                TravelerProfile profile = await ProfileManager.LoadUserAndTravelerProfile(User);

                if (profile != null)
                {
                    using (var db = new ApplicationDbContext())
                    {
                        profile = await LoadProfile(profile.ID);

                        Models.VM.TravelerProfileVM profileVM = new Models.VM.TravelerProfileVM(profile);

                        return(View(profileVM));
                    }
                }
                else
                {
                    return(RedirectToAction("Create"));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                return(RedirectToAction("Index", "Home"));
            }
        }
        public async Task <ActionResult> Details(int?id)
        {
            try
            {
                TravelerProfile tp;
                TravelerProfile tpcheck;
                bool            user = false;
                if (id == null) /// load own ProfileDetails
                {
                    tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                    tp = await LoadProfile(tp.ID);

                    user = true;
                }
                else
                {
                    tp = await LoadProfile(id.Value);

                    tpcheck = await ProfileManager.LoadUserAndTravelerProfile(User);

                    if (tp.ID == tpcheck.ID)
                    {
                        user = true;
                    }
                }


                Models.VM.TravelerProfileVM profileVM = LoadTravelerVM(tp);
                int i = 0;
                foreach (var rev in tp.Reviews.Reviews)
                {
                    Models.VM.ProfilePreviewVM poster = await ProfilePreviewVM(rev.TravelerPoster_ID);

                    profileVM.ReviewsVM.Reviews[i].Poster = poster;
                    i++;
                }
                profileVM.User = user;
                if (!user)
                {
                    profileVM.createReview = new Models.VM.CreateReviewVM(id.Value);
                }

                return(View(profileVM));
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                return(RedirectToAction("Index", "Home"));
            }
        }
 public void SetValues(Models.VM.TravelerProfileVM tPVM) //only for update
 {
     Description.Age         = tPVM.DescriptionVM.Age.ToString("dd.MM.yyyy");
     Description.Name        = tPVM.DescriptionVM.Name;
     Description.Sex         = tPVM.DescriptionVM.Sex;
     Description.Text        = tPVM.DescriptionVM.Text;
     Attributes.Currency     = tPVM.AttributesVM.Currency;
     Attributes.Language     = "en"; //has to be changed when language is implemented
     Attributes.HasPets      = tPVM.AttributesVM.HasPets;
     Attributes.IsSmoking    = tPVM.AttributesVM.IsSmoking;
     Attributes.IsVegetarian = tPVM.AttributesVM.IsVegetarian;
     Attributes.NoiseLevel   = tPVM.AttributesVM.NoiseLevel;
     Attributes.Nomad        = tPVM.AttributesVM.Nomad;
     Attributes.Yoga         = tPVM.AttributesVM.Yoga;
 }
        public async Task <ActionResult> Create(Models.VM.TravelerProfileVM travelerProfile)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                    user        = await userManager.FindByEmailAsync(User.Identity.Name);

                    TravelerProfile profile = new TravelerProfile();
                    PopulateTavelerProfile(profile);
                    profile.SetValues(travelerProfile);
                    Picture pic = ImageProcessing.ReadPicture(travelerProfile.DescriptionVM.upload);
                    if (pic != null)
                    {
                        profile.Description.ProfilePic = pic;
                    }
                    else
                    {
                        profile.Description.ProfilePic = ImageProcessing.ReadPicture(Server.MapPath("~/Images/ProfileBlankPic.png"));
                    }

                    profile.TimeStamp = DateTime.Now;
                    using (var db = new ApplicationDbContext())
                    {
                        db.TravelerProfile.Add(profile);
                        await db.SaveChangesAsync();
                    }
                    user.ProfileID = profile.ID;
                    user.UserType  = "Traveler";
                    await userManager.UpdateAsync(user);

                    NotificationManager.AddNotification(NotificationType.Success, "Travelerprofile successful created");
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    NotificationManager.AddException(e);
                    return(View(travelerProfile));
                }
            }

            return(View(travelerProfile));
        }
        public async Task <ActionResult> Index()
        {
            if (User != null)
            {
                ///Load TravelerInfos Mailbox, Requests, RoomRequests

                TravelerProfile profile = await ProfileManager.LoadUserAndTravelerProfile(User);

                if (profile != null)
                {
                    profile = await LoadProfile(profile.ID);

                    Models.VM.TravelerProfileVM profileVM = new Models.VM.TravelerProfileVM(profile);

                    return(View(profileVM));
                }
            }

            return(RedirectToAction("Create"));
        }
        public async Task <ActionResult> Edit(Models.VM.TravelerProfileVM tpVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                    if (tp != null)
                    {
                        using (var db = new ApplicationDbContext())
                        {
                            tp = await LoadProfile(tp.ID);//tp is the updated version

                            TravelerProfile travelerDB = db.TravelerProfile.Find(tp.ID);
                            var             Attributes = await db.TravelerProfileAttributes.FindAsync(tp.TravelerAttributesID);

                            var Description = await db.TravelerProfileDescription.FindAsync(tp.TravelerProfileDescriptionID);

                            var ProfilePic = await db.Pictures.FindAsync(tp.Description.ProfilePic_ID);

                            tp.SetValues(tpVM); //setting old values w/o picture


                            //db.Entry(travelerDB).CurrentValues.SetValues(tp);
                            tp.Attributes.ID = Attributes.ID;
                            db.Entry(Attributes).CurrentValues.SetValues(tp.Attributes);

                            if (ProfilePic != null)                    /// old picture exists           ///Check tp here!! IDs
                            {
                                if (tpVM.DescriptionVM.upload != null) //new upload exists
                                {
                                    //overwrite old Pic


                                    Picture newPic = ImageProcessing.ReadPicture(tpVM.DescriptionVM.upload);

                                    newPic.ID = ProfilePic.ID; //Setting id of old pic id
                                    tp.Description.ProfilePic_ID = newPic.ID;
                                    tp.Description.ProfilePic    = newPic;

                                    db.Entry(ProfilePic).CurrentValues.SetValues(tp.Description.ProfilePic);
                                    db.Entry(Description).CurrentValues.SetValues(tp.Description); //kann denn raus
                                }
                                //do nothing with Pic
                                tp.Description.ID = Description.ID;
                                db.Entry(Description).CurrentValues.SetValues(tp.Description);
                            }
                            else //no old pic exists
                            {
                                if (tpVM.DescriptionVM.upload != null) //new upload exists
                                {
                                    tp.Description.ProfilePic = ImageProcessing.ReadPicture(tpVM.DescriptionVM.upload);
                                    db.Pictures.Add(tp.Description.ProfilePic);
                                    tp.Description.ID = Description.ID;
                                    db.Entry(Description).CurrentValues.SetValues(tp.Description);
                                }
                                tp.Description.ID = Description.ID;
                                db.Entry(Description).CurrentValues.SetValues(tp.Description);
                            }
                            await db.SaveChangesAsync();
                        }
                        NotificationManager.AddNotification(NotificationType.Success, "Profile update successful");
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                catch (Exception e)
                {
                    NotificationManager.AddException(e);
                }
            }
            return(View(tpVM));
        }
        public ActionResult Create()
        {
            Models.VM.TravelerProfileVM travelerProfileVM = new Models.VM.TravelerProfileVM();

            return(View(travelerProfileVM));
        }