コード例 #1
0
ファイル: Controller.cs プロジェクト: vnikifirov/DotNet
        public static Data.Rating SaveRating(IDBSession dbs, Data.Rating rating)
        {
            using (NHibernate.ITransaction transaction = dbs.Session.BeginTransaction())
            {
                DB.Rating dbRating = null;
                if (rating.MessageID != Guid.Empty)
                {
                    dbRating = dbs.Session.Get <DB.Rating>(rating.MessageID);
                }
                if (dbRating == null)
                {
                    dbRating = new DB.Rating(rating);
                }
                else
                {
                    dbRating.Value = rating.Value;
                }

                DB.Message dbMessage = dbs.Session.QueryOver <DB.Message>().Fetch(x => x.Comments).Eager.Where(x => x.ID == rating.MessageID).SingleOrDefault <DB.Message>();
                if (dbMessage != null)
                {
                    //if (dbMessage.Ratings == null) dbMessage.Ratings = new List<Rating>();
                    dbMessage.Ratings.Add(dbRating);
                    dbs.Session.SaveOrUpdate(dbMessage);
                    transaction.Commit();
                    rating = dbRating.ToData();
                }
            }
            return(rating);
        }
コード例 #2
0
ファイル: ProfessorController.cs プロジェクト: austinmm/TAhub
        //********** AJAX METHODS **********//
        //***** Message TAs AJAX ***** (made from Professor ViewTAs View Page)
        public JsonResult MessageTAs(string TAs, string text)
        {
            string         response = "Unable to message TAs sepcified.";
            ProfessorModel user     = Cache.GetUser <ProfessorModel>();

            if (user == null)
            {
                response = "Issue obtaining account details. Please sign out and back in again.";
            }
            List <string> Ids = TAs.Split(',').ToList();

            if (Ids != null && Ids.Count > 0 && !String.IsNullOrWhiteSpace(text) && user != null)
            {
                foreach (string TA_Id in Ids)
                {
                    if (Int32.TryParse(TA_Id, out int Id))
                    {
                        DB.Message message = new DB.Message();
                        message.TeachersAssistantId = Id;
                        message.SenderType          = "Professor";
                        message.SenderName          = $"{user.FirstName} {user.LastName}";
                        message.SenderEmail         = user.Login.Username;
                        message.Text = text;
                        string errors = DB.DBMethods.Insert(message);
                    }
                }
                Response.StatusCode = (int)HttpStatusCode.OK;
                return(Json("Success", MediaTypeNames.Text.Plain));
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(response, MediaTypeNames.Text.Plain));
        }
コード例 #3
0
ファイル: Controller.cs プロジェクト: vnikifirov/DotNet
        public static Data.Message SaveMessage(IDBSession dbs, Data.Message message)
        {
            using (NHibernate.ITransaction transaction = dbs.Session.BeginTransaction())
            {
                DB.Message dbMessage = null;
                if (message.ID != Guid.Empty)
                {
                    dbMessage = dbs.Session.Get <DB.Message>(message.ID);
                }
                if (dbMessage == null)
                {
                    dbMessage         = new DB.Message(message);
                    dbMessage.Created = DateTime.UtcNow;
                }
                else
                {
                    dbMessage.Author  = message.Author;
                    dbMessage.Title   = message.Title;
                    dbMessage.Content = message.Content;
                }

                dbs.Session.SaveOrUpdate(dbMessage);
                transaction.Commit();
                message = dbMessage.ToData(false, true);
            }
            return(message);
        }
コード例 #4
0
        public async Task <ActionResult <Result> > NewMessage([FromForm] string author, [FromForm] string content)
        {
            if (string.IsNullOrWhiteSpace(author))
            {
                author = "匿名";
            }

            if (string.IsNullOrWhiteSpace(content))
            {
                return(Accepted(value: Result.Rtn(message: "内容不能为空")));
            }

            DB.Message newMessage = new DB.Message
            {
                Author  = author,
                Content = content
            };
            _db.Messages.Add(newMessage);
            if (await _db.SaveChangesAsync() == 1)
            {
                return(Created("", Result.Rtn(message: "成功", data: newMessage.Id)));
            }
            else
            {
                return(Accepted(value: Result.Rtn(message: "失败")));
            }
        }
コード例 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // TODO check if message belongs to the current user

            int messageID = int.Parse(Request.QueryString["ID"]);

            // recipients and destinations will be deleted via db diagram voila :)
            DB.Message message = DB.Message.Get(messageID);
            if (message != null)
            {
                message.Delete();
            }
        }
コード例 #6
0
 public ActionResult Contact(MessageModel message)
 {
     //Ensures that the message paramter is instatiated
     if (message != null)
     {
         //Converts the Message object to a Database object
         DB.Message DB_Message = DB.DBMethods.Message_ModelToDB(message);
         //Inserts the Message into the Database
         string errors = DB.DBMethods.Insert(DB_Message);
         //If the Message was successfully inserted into the database
         if (String.IsNullOrWhiteSpace(errors))
         {
             return(RedirectToAction(actionName: "Contact", controllerName: "TA", routeValues: new { notification = "Success, Your Message has been Sent!" }));
         }
     }
     return(RedirectToAction(actionName: "Contact", controllerName: "TA", routeValues: new { notification = "We are unable to Process you request at this time." }));
 }
コード例 #7
0
 public JsonResult DeleteMessage(string Id)
 {
     //Attempts to convert the string representation of the Message Id to an int
     if (Int32.TryParse(Id, out int ID))
     {
         //Attempts to delete the message from the database
         if (DB.DBMethods.Delete_Message(ID))
         {
             //Updates the cached TA to represent the updated message state
             TAModel    TA      = Cache.GetUser <TAModel>();
             DB.Message message = TA.Messages.FirstOrDefault(x => x.Id == ID);
             TA.Messages.Remove(message);
             Cache.Set(TA);
             Response.StatusCode = (int)HttpStatusCode.OK;
             return(Json("Message has been Successfully Deleted", MediaTypeNames.Text.Plain));
         }
     }
     Response.StatusCode = (int)HttpStatusCode.BadRequest;
     return(Json("Failed to Delete Message", MediaTypeNames.Text.Plain));
 }
コード例 #8
0
ファイル: Controller.cs プロジェクト: vnikifirov/DotNet
        public static Data.Comment SaveComment(IDBSession dbs, Data.Comment comment)
        {
            using (NHibernate.ITransaction transaction = dbs.Session.BeginTransaction())
            {
                DB.Comment dbComment = null;
                if (comment.ID != Guid.Empty)
                {
                    dbComment = dbs.Session.Get <DB.Comment>(comment.ID);
                }
                if (dbComment == null)
                {
                    dbComment         = new DB.Comment(comment);
                    dbComment.Created = DateTime.UtcNow;
                }
                else
                {
                    dbComment.Author  = comment.Author;
                    dbComment.Content = comment.Content;
                }


                DB.Message dbMessage = dbs.Session.QueryOver <DB.Message>().Fetch(x => x.Comments).Eager.Where(x => x.ID == comment.MessageID).SingleOrDefault <DB.Message>();
                if (dbMessage != null)
                {
                    dbMessage.Comments.Add(dbComment);
                    dbs.Session.SaveOrUpdate(dbMessage);
                    transaction.Commit();
                    comment = dbComment.ToData(false);
                }
                else
                {
                    dbs.Session.SaveOrUpdate(dbComment);
                    transaction.Commit();
                    comment = dbComment.ToData(false);
                }
            }
            return(comment);
        }
コード例 #9
0
ファイル: Controller.cs プロジェクト: vnikifirov/DotNet
 public static Data.Message LoadMessage(IDBSession dbs, Guid id)
 {
     DB.Message   dbMessage = dbs.Session.QueryOver <DB.Message>().Fetch(x => x.Comments).Eager.Where(x => x.ID == id).SingleOrDefault <DB.Message>();
     Data.Message message   = dbMessage?.ToData(true, true);
     return(message);
 }