Ejemplo n.º 1
0
        public ActionResult Like(int messageId)
        {
            using (var db = new MessimContext())
            {
                var message = db.Messages.SingleOrDefault(x => x.ID == messageId);

                if (message == null)
                {
                    //FIXME: log error
                    return new JsonResult() { Data = new { ConsoleMessage = "no such message in DB" } };
                }

                message.LikeAmount += 1;
                db.Entry(message).State = EntityState.Modified;
                db.SaveChanges();
                return new JsonResult { Data = new { ConsoleMessage = "Message with " + messageId + " liked" } };
            }
        }
Ejemplo n.º 2
0
        public ActionResult Register(string username, string password, string passwordAgain)
        {
            if (!ValidateRegister(username, password, passwordAgain))
            {
                return View();
            }
            using (var _db = new MessimContext())
            {
                User newUser = new User { Username = username, Password = SHA.CreateSHA1Hash(password) };
                _db.Users.Add(newUser);
                _db.SaveChanges();
            }

            ViewBag.Success = true;
            return View();
        }
Ejemplo n.º 3
0
 public JsonResult Send(string messageText, HttpPostedFileBase messageImage)
 {
     string path = null;
     if (messageImage.ContentLength > 0)
     {
         var fileName = Path.GetFileName(messageImage.FileName);
         path = Path.Combine(Server.MapPath("~/Content/uploads"), fileName);
         messageImage.SaveAs(path);
     }
     var image = new Bitmap(path);
     using (var db = new MessimContext())
     {
         var user = db.Users.Single(x => x.Username == User.Identity.Name);
         var newImage = new Image { URL = "/Content/uploads/" + Path.GetFileName(messageImage.FileName), Width = image.Width, Height = image.Height };
         var newMessage = new Message { Text = messageText, Date = DateTime.Now, LikeAmount = 0, Sender = user, Image = newImage };
         db.Messages.Add(newMessage);
         db.SaveChanges();
     }
     // Return JSON
     return new JsonResult { Data = new { Msg = "Success" } };
 }