Beispiel #1
0
        public ActionResult FinishSetup(HttpPostedFileBase file, FinishSetupViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            char?  gender    = model.Gender;
            int?   cityId    = model.CityId;
            string interests = model.Interests;

            DapperRepository repo        = new DapperRepository();
            ApplicationUser  CurrentUser = repo.GetCurrentUser();

            if (CurrentUser.SetupCompleted)
            {
                return(HttpNotFound());
            }

            string SavePath   = null;
            string ImgRelPath = null;

            string[] tokens = null;
            if (file != null)
            {
                string pic = CurrentUser.Id + System.IO.Path.GetExtension(file.FileName);
                Debug.WriteLine(pic);
                SavePath = System.IO.Path.Combine(
                    Server.MapPath("~/images/a"), pic);
                // file is uploaded
                file.SaveAs(SavePath);
                //Conversion to jpg( throws exceptions)
                if (!System.IO.Path.GetExtension(file.FileName).Equals(".jpg"))
                {
                    System.Drawing.Image image = System.Drawing.Image.FromFile(SavePath);
                    SavePath = System.IO.Path.Combine(Server.MapPath("~/images/a"), CurrentUser.Id + ".jpg");
                    System.IO.File.Delete(SavePath);
                    image.Save(SavePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                ImgRelPath = "/images/a/" + CurrentUser.Id + ".jpg";
                //Debug.WriteLine(path);
            }

            /*if (gender != null)
             * {
             *  Debug.WriteLine("Gender:" + gender);
             * }
             * if (cityId != null)
             * {
             *  Debug.WriteLine("CityId:" + cityId);
             * }*/
            if (interests != null)
            {
                tokens = interests.Split(',');
                repo.SetInterests(CurrentUser, tokens);
                //Debug:

                /*foreach (var item in tokens)
                 * {
                 *  Debug.WriteLine("Interest:" + item.ToLower());
                 * }
                 * Debug.WriteLine("Interests:" + interests);*/
            }
            repo.FinishSetup(CurrentUser, ImgRelPath, gender, cityId);
            return(RedirectToAction("Index", "Chat"));
        }