public ActionResult Index(Models.EcoPathModel model, HttpPostedFileBase file)
        {
            var _context = new EcoPathDBEntities();

            var id = (from u in _context.User_Accounts
                      where u.Username == User.Identity.Name
                      select u.Id).FirstOrDefault();

            if (id != null)
            {
                if (!String.IsNullOrEmpty(model.newCommText))
                {
                    var newComment = new Comment
                    {
                        EcoPathId = model.entId,
                        UserId    = id,
                        Text      = model.newCommText,
                        Date      = DateTime.Now
                    };

                    _context.Comments.AddObject(newComment);
                    _context.SaveChanges();
                }

                if (file != null && file.ContentLength > 0)
                {
                    var fileName   = Path.GetFileName(file.FileName);
                    var fileTitle  = fileName.Substring(0, fileName.LastIndexOf('.'));
                    var folderPath = HttpRuntime.AppDomainAppPath + @"\Content\Images\" + model.entId;

                    var count = 1;
                    while (System.IO.File.Exists(Path.Combine(folderPath, fileName)))
                    {
                        var imageName = fileName.Substring(0, fileName.LastIndexOf('.'));
                        var imageType = fileName.Substring(fileName.LastIndexOf('.'));
                        fileName = imageName + "(" + count + ")" + imageType;
                    }
                    var path = Path.Combine(folderPath, fileName);
                    file.SaveAs(path);

                    var newImage = new Image
                    {
                        EcoPathId = 1,
                        UserId    = id,
                        ImageName = fileName,
                        Title     = fileTitle
                    };

                    _context.Images.AddObject(newImage);
                    _context.SaveChanges();
                }
            }
            return(RedirectToAction("Index", new { id = model.entId }));
        }
Beispiel #2
0
        /// <summary>
        /// Adds the new user into the database
        /// </summary>
        public void Create()
        {
            User_Account newUser = User_Account.CreateUser_Account(Guid.NewGuid(), UserName,
                                                                   Helpers.SHA1.Encode(Password), DateTime.Now, Email, false);

            _context.AddToUser_Accounts(newUser);
            _context.SaveChanges();

            User_Info newUserInfo = User_Info.CreateUser_Info(newUser.Id);

            _context.AddToUser_Info(newUserInfo);
            _context.SaveChanges();
        }
Beispiel #3
0
        /// <summary>
        /// Commits the changes to the User into the database
        /// </summary>
        public void Save()
        {
            var entity = (from ui in _context.User_Info
                          where ui.Id == id
                          select ui).FirstOrDefault();

            if (String.IsNullOrEmpty(FirstName) && String.IsNullOrWhiteSpace(FirstName))
            {
                entity.FirstName = null;
            }
            else
            {
                entity.FirstName = FirstName;
            }

            if (String.IsNullOrEmpty(MiddleName) && String.IsNullOrWhiteSpace(MiddleName))
            {
                entity.MiddleName = null;
            }
            else
            {
                entity.MiddleName = MiddleName;
            }

            if (String.IsNullOrEmpty(LastName) && String.IsNullOrWhiteSpace(LastName))
            {
                entity.LastName = null;
            }
            else
            {
                entity.LastName = LastName;
            }

            entity.City = SelectedCity;

            entity.Age = Age;

            if (Gender == "m" || Gender == "f")
            {
                entity.Gender = Gender;
            }

            if (!String.IsNullOrEmpty(OldPassword) && !String.IsNullOrWhiteSpace(OldPassword) &&
                !String.IsNullOrEmpty(NewPassword))
            {
                entity.User_Accounts.Password = NewPassword;
            }

            _context.User_Info.ApplyCurrentValues(entity);
            _context.SaveChanges();
        }
Beispiel #4
0
 public ActionResult Verify(string id)
 {
     if (string.IsNullOrEmpty(id) || (!Regex.IsMatch(id, @"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}")))
     {
         ViewBag.Msg = "Грешен линк";
         return(View());
     }
     else
     {
         EcoPathDBEntities _context = new EcoPathDBEntities();
         User_Account      user     = (from ua in _context.User_Accounts
                                       where ua.Id == new Guid(id)
                                       select ua).FirstOrDefault();
         if (user != null)
         {
             if (!user.Confirmed)
             {
                 user.Confirmed = true;
                 _context.SaveChanges();
                 ViewBag.Msg = "Вие успешно потвърдихте Вашият потребителски акаунт! Ще бъдете прехвърлени на началната страница след 5 секунди.";
                 FormsAuthentication.SetAuthCookie(user.Username, false);
                 return(View());
             }
             else
             {
                 FormsAuthentication.SignOut();
                 ViewBag.Msg = "Този потребителски акаунт е вече потвърден";
                 return(View());
             }
         }
         else
         {
             FormsAuthentication.SignOut();
             ViewBag.Msg = "Не съществува потребител с този код.";
             return(View());
         }
     }
 }