Пример #1
0
        public ActionResult EditProfile(int id, FormCollection profil)
        {
            try
            {
                using (Gr8DbContext gr8Db = new Gr8DbContext())
                {
                    var result = gr8Db.Users.SingleOrDefault(o => o.Id == id);
                    result.FirstName = Request["FirstName"];
                    result.LastName  = Request["LastName"];

                    string   dateInput  = Request["DateOfBirth"];
                    DateTime parsedDate = DateTime.Parse(dateInput);
                    result.DateOfBirth = parsedDate;

                    var lista1 = gr8Db.Database.SqlQuery <string>("Select Name From Interests");
                    var lista2 = gr8Db.Database.SqlQuery <string>("Select Name From Interests Join UserInterests On Interests.Id = UserInterests.Interest Where UserId ='" + id.ToString() + "'");

                    gr8Db.SaveChanges();
                }
                return(Redirect(Url.Action("MyProfile", "Profile")));
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View("Error"));
            }
        }
Пример #2
0
        public ActionResult AddImageForm(Image image)

        {
            try
            {
                int    thisId   = ThisUser();
                string fileName = Path.GetFileNameWithoutExtension(image.ImageFile.FileName);
                string fileExt  = Path.GetExtension(image.ImageFile.FileName);
                fileName      = fileName + DateTime.Now.ToString("yymmdd") + fileExt;
                image.ImgPath = "~/Images/UserImages/" + fileName;
                image.Title   = fileName;
                image.UserId  = thisId;
                fileName      = Path.Combine(Server.MapPath("~/Images/UserImages/"), fileName);

                image.ImageFile.SaveAs(fileName);

                var ctx = new Gr8DbContext();
                ctx.Images.Add(image);
                ctx.Database.ExecuteSqlCommand("Update Users Set ProfileImage = '" + image.ImgPath + "' where Id = '" + thisId.ToString() + "'");

                ctx.SaveChanges();
                return(RedirectToAction("MyProfile", "Profile"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View("Error"));
            }
        }
 public string Send([FromBody] Posts thePost)
 {
     try
     {
         ctx.Posts.Add(thePost);
         ctx.SaveChanges();
         return("Meddelandet skickat");
     }
     catch {
         return("Något gick fel!");
     }
 }
Пример #4
0
 public ActionResult ActivateAccount()
 {
     try
     {
         int id  = ThisUser();
         var ctx = new Gr8DbContext();
         ctx.Database.ExecuteSqlCommand("Update Users Set Active = 'True' Where Id =" + id);
         ctx.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(View("Error"));
     }
 }
Пример #5
0
        public ActionResult AddUser(User model)
        {
            try
            {
                var ctx = new Gr8DbContext();
                model.Active = true;
                ctx.Users.Add(model);
                ctx.SaveChanges();

                return(Redirect(Url.Action("MyProfile", "Profile")));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View("Error"));
            }
        }
Пример #6
0
        public ActionResult FriendRequest(int Id)
        {
            try
            {
                int myId     = ThisUser();
                int friendId = Id;
                var ctx      = new Gr8DbContext();

                ctx.Database.ExecuteSqlCommand("Insert into FriendRequests values(" + myId + ", " + friendId + ", 'False') ");
                ctx.SaveChanges();
                return(RedirectToAction("MyFriends", "Profile"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View("Error"));
            }
        }
Пример #7
0
        //Ta bort det valda intresset från listan.
        public ActionResult DeleteInterestFromList(int Id)
        {
            try
            {
                var MyId = ThisUser();
                var ctx  = new Gr8DbContext();
                ctx.Database.ExecuteSqlCommand("Delete From UserInterests Where UserId=" + MyId + " And Interest=" + Id);

                ctx.SaveChanges();

                return(RedirectToAction("MyProfile", "Profile"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View("Error"));
            }
        }
Пример #8
0
        public ActionResult DenyFriendRequest(int?id)
        {
            try
            {
                var MyId = ThisUser();

                var ctx = new Gr8DbContext();

                ctx.Database.ExecuteSqlCommand("delete from FriendRequests Where FromUser = '******' and ToUser = '******'");
                ctx.SaveChanges();

                return(RedirectToAction("MyFriends", "Profile"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View("Error"));
            }
        }
Пример #9
0
        public ActionResult DeleteInterest(FormCollection profil)
        {
            try
            {
                var MyId = ThisUser();

                var    ctx      = new Gr8DbContext();
                string intresse = Request["Interest.Name"];

                ctx.Database.ExecuteSqlCommand("Delete From UserInterests Where UserId=" + MyId + " And Interest=(Select Id From Interests where Name='" + intresse + "')");
                ctx.SaveChanges();

                return(RedirectToAction("MyProfile", "Profile"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View("Error"));
            }
        }
Пример #10
0
        //Lägger till intresset som man väljer från listan med redan befintliga intressen.
        public ActionResult AddInterestFromList(int Id)
        {
            try
            {
                var  MyId     = ThisUser();
                var  ctx      = new Gr8DbContext();
                var  intresse = ctx.Database.SqlQuery <string>("Select Name From Interests Where Id ='" + Id.ToString() + "'").FirstOrDefault();
                var  lista1   = ctx.Database.SqlQuery <string>("Select Name From Interests").ToList();
                bool boolean  = true;
                foreach (var namn in lista1)
                {
                    if (intresse.Equals(namn))
                    {
                        boolean = false;
                    }
                }

                if (boolean)
                {
                    ctx.Database.ExecuteSqlCommand("Insert into Interests Values('" + intresse + "')");
                    ctx.Database.ExecuteSqlCommand("Insert into UserInterests Values(" + MyId + ", (Select Id From Interests Where Name='" + intresse + "'))");
                }

                else
                {
                    ctx.Database.ExecuteSqlCommand("Insert into UserInterests Values(" + MyId + ", (Select Id From Interests Where Name='" + intresse + "'))");
                }

                ctx.SaveChanges();

                return(RedirectToAction("MyProfile", "Profile"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View("Error"));
            }
        }
Пример #11
0
 //Profilsidan som visas när man går in på någon annans profilsida.
 public ActionResult OtherProfile(int id)
 {
     try
     {
         var myId      = ThisUser();
         var time      = DateTime.Now;
         var ctx       = new Gr8DbContext();
         var viewModel = new OtherProfileViewModel
         {
             OtherUser            = ctx.Users.Where(i => i.Id == id).FirstOrDefault(),
             OtherUserInterests   = ctx.Database.SqlQuery <string>("select Name from Interests join UserInterests on UserInterests.Interest=Interests.Id where UserInterests.UserId ='" + id.ToString() + "'").ToList(),
             FriendControl        = ctx.Database.SqlQuery <int>("Select Count(*) From FriendRequests Where FromUser = "******" and ToUser = "******" and Accepted = 'True' or ToUser = "******" and FromUser = "******" and Accepted = 'True'").Sum(),
             FriendRequestControl = ctx.Database.SqlQuery <int>("Select Count(*) From FriendRequests Where FromUser = "******" and ToUser = "******" and Accepted = 'False' or ToUser = "******" and FromUser = "******" and Accepted = 'False'").Sum()
         };
         ctx.Database.ExecuteSqlCommand("Insert into Visitors Values (" + myId + ", " + id + ", '" + time + "')");
         ctx.SaveChanges();
         return(View(viewModel));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(View("Error"));
     }
 }