Beispiel #1
0
 public ActionResult Index()
 {
     using (EntityContext db = new EntityContext())
     {
         ViewBag.Users=db.Users.OrderByDescending(r => r.Rating).Take(10).ToList();
         return View(db.Events.OrderBy(r=> r.EventAt).ToList());
     }
 }
Beispiel #2
0
        //
        // GET: /Profile/Edit
        public ActionResult Edit()
        {
            using (EntityContext db = new EntityContext())
            {
                User user = db.Users.Find(WebSecurity.GetUserId(User.Identity.Name));

                return View(user);
            }
        }
Beispiel #3
0
 public ActionResult Edit(User user)
 {
     using (EntityContext db = new EntityContext())
     {
         if (ModelState.IsValid)
         {
             db.Entry(user).State = EntityState.Modified;
             db.SaveChanges();
             return RedirectToAction("Index");
         }
         return View(user);
     }
 }
Beispiel #4
0
 public ActionResult Index()
 {
     using (EntityContext db = new EntityContext())
     {
         User user = db.Users.Find(WebSecurity.GetUserId(User.Identity.Name));
         var allInterests = user.Interests;
         var viewModel = new List<Interest>();
         foreach (var interest in allInterests)
         {
             viewModel.Add(new Interest
             {
                 InterestId = interest.InterestId,
                 Name = interest.Name,
             });
         }
         ViewBag.events =user.Events.ToList();
         ViewBag.interests = viewModel;
         return View(user);
     }
 }
Beispiel #5
0
        public ActionResult Index(HttpPostedFileBase fileUpload)
        {
            using (EntityContext db = new EntityContext())
            {
                User user = db.Users.Find(WebSecurity.GetUserId(User.Identity.Name));

                if (fileUpload != null)
                {
                    string path = Server.MapPath("~/Images/");
                    if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                    string filename = Path.GetFileName(fileUpload.FileName);
                    if (filename != null)
                    {
                        Image image = ImageUpload.ResizeFile(fileUpload, 228,266);
                        image.Save(Path.Combine(path, filename));
                        user.Avatar = Path.Combine("/images/", filename);
                        db.SaveChanges();
                    }
                }
            }
            return RedirectToAction("Index");
        }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer<EntityContext>(null);

                try
                {
                    using (var context = new EntityContext())
                    {
                        if (!context.Database.Exists())
                        {
                            // Создание базы данных SimpleMembership без схемы миграции Entity Framework
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("EntityContext", "Users", "UserId", "Email", autoCreateTables: true);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("Не удалось инициализировать базу данных ASP.NET Simple Membership. Чтобы получить дополнительные сведения, перейдите по адресу: http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }
Beispiel #7
0
        //
        // GET: /Event/Details/5
        public ActionResult About(int id = 0)
        {
            using (EntityContext db = new EntityContext())
            {
                Event fact = db.Events.Find(id);
                if (fact == null)
                {
                    return HttpNotFound();
                }
                var allInterests = fact.Interests;
                var viewModel = new List<Interest>();
                foreach (var interest in allInterests)
                {
                    viewModel.Add(new Interest
                    {
                        InterestId = interest.InterestId,
                        Name = interest.Name,
                    });
                }
                ViewBag.interests = viewModel;
                var eventToCheck = db.Events
                 .Where(i => i.EventId == id)
                 .Single();
                int x = WebSecurity.GetUserId(User.Identity.Name);
                User user = db.Users.Find(WebSecurity.GetUserId(User.Identity.Name));
                bool userCheck = false;

                if (eventToCheck.Users.Contains(user))
                {
                    userCheck = true ;
                }

                ViewBag.Describe = userCheck;

                return View(fact);
            }
        }
Beispiel #8
0
        public ActionResult About(bool userCheck,Event fact)
        {
            using (EntityContext db = new EntityContext())
            {
                User user = db.Users.Find(WebSecurity.GetUserId(User.Identity.Name));
                var eventToCheck = db.Events
                 .Where(i => i.EventId == fact.EventId)
                 .Single();

                if (userCheck == false)
                {
                    eventToCheck.Users.Add(user);
                    user.Rating++;
                }
                else
                {
                    eventToCheck.Users.Remove(user);
                    user.Rating--;

                }
                db.SaveChanges();
            }
            return RedirectToAction("About", new { id = fact.EventId });
        }
Beispiel #9
0
        //
        // GET: /Profile/Users/5
        public ActionResult Profile(int id = 0)
        {
            using (EntityContext db = new EntityContext())
            {
                User user = db.Users.Find(id);
                if (user == null)
                {
                    return HttpNotFound();
                }
                var allInterests = user.Interests;
                var viewModel = new List<Interest>();
                foreach (var interest in allInterests)
                {
                    viewModel.Add(new Interest
                    {
                        InterestId = interest.InterestId,
                        Name = interest.Name,
                    });
                }
                ViewBag.events = user.Events.ToList();
                ViewBag.interests = viewModel;

                return View(user);
            }
        }
Beispiel #10
0
        //
        // GET: /Event/Create
        public ActionResult Create()
        {
            using (EntityContext db = new EntityContext())
            {

                var allInterests = db.Interests;
                var viewModel = new List<Interest>();
                foreach (var interest in allInterests)
                {
                    viewModel.Add(new Interest
                    {
                        InterestId = interest.InterestId,
                        Name = interest.Name,
                    });
                }
                ViewBag.Interests = viewModel;
            }

            return View();
        }
Beispiel #11
0
 // private EntityContext db = new EntityContext();
 //
 // GET: /Event/
 public ActionResult Index()
 {
     using (EntityContext db = new EntityContext())
         return View(db.Events.ToList());
 }
Beispiel #12
0
 public ActionResult DeleteConfirmed(int id)
 {
     using (EntityContext db = new EntityContext())
     {
         Event fact = db.Events.Find(id);
         db.Events.Remove(fact);
         db.SaveChanges();
     }
     return RedirectToAction("Index");
 }
Beispiel #13
0
 //
 // GET: /Event/Delete/5
 public ActionResult Delete(int id = 0)
 {
     using (EntityContext db = new EntityContext())
     {
         Event fact = db.Events.Find(id);
         if (fact == null)
         {
             return HttpNotFound();
         }
         return View(fact);
     }
 }
Beispiel #14
0
        public ActionResult Create(Event fact, string[] selectedInterests)
        {
            if (ModelState.IsValid)
            {
                using (EntityContext db = new EntityContext())
                {
                    db.Events.Add(fact);
                    db.SaveChanges();
                }
                using (EntityContext db = new EntityContext())
                {
                    var userToUpdate = db.Events
                 .Where(i => i.EventId == fact.EventId)
                 .Single();
                    var selectedInterestsHs = new HashSet<string>(selectedInterests);
                    foreach (var interest in db.Interests)
                    {
                        if (selectedInterestsHs.Contains(interest.InterestId.ToString()))
                        {

                            userToUpdate.Interests.Add(interest);

                        }
                    }

                    db.SaveChanges();
                }
                return RedirectToAction("Index");
            }

            return View();
        }
Beispiel #15
0
        public ActionResult Register(RegisterModel model,string[] selectedInterests)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    WebSecurity.CreateUserAndAccount(model.Email, model.Password,
                        new { FirstName = model.FirstName, LastName = model.LastName, About = model.About, Rating = 0, Avatar = "/images/Default.jpg"});
                    WebSecurity.Login(model.Email, model.Password);
                    using (EntityContext db = new EntityContext())
                    {
                        User userToUpdate = db.Users.Find(WebSecurity.GetUserId(model.Email));
                            var selectedInterestsHs = new HashSet<string>(selectedInterests);
                        foreach (var interest in db.Interests)
                        {
                            if (selectedInterestsHs.Contains(interest.InterestId.ToString()))
                            {

                                userToUpdate.Interests.Add(interest);

                            }
                        }
                        db.SaveChanges();
                    }
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }
            using (EntityContext db = new EntityContext())
            {

                var allInterests = db.Interests;
                var viewModel = new List<Interest>();
                foreach (var interest in allInterests)
                {
                    viewModel.Add(new Interest
                    {
                        InterestId = interest.InterestId,
                        Name = interest.Name,
                    });
                }
                ViewBag.Interests = viewModel;
            }
            return View(model);
        }
Beispiel #16
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Добавление нового пользователя в базу данных
                using (EntityContext db = new EntityContext())
                {
                    User user = db.Users.FirstOrDefault(u => u.Email.ToLower() == model.Email.ToLower());
                    // Проверка наличия пользователя в базе данных
                    if (user == null)
                    {
                        // Добавление имени в таблицу профиля
                        db.Users.Add(new User { Email = model.Email });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.Email);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "Email already exists.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }