Esempio n. 1
0
        public IHttpActionResult AddMessage(int ConservationId, string newMessage)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(User.Identity.Name).UserID;
            }
            Message mess = new Message();

            mess.ConservationId = ConservationId;
            mess.Content        = newMessage;
            mess.CreatedDate    = DateTime.Now;
            mess.UserId         = CurrenUser;
            mess.Status         = true;
            using (var db = new ConservationDAL())
            {
                db.AddNewMessage(mess);
                Conversation current = db.GetConservationById(ConservationId);
                current.UpdatedTime = DateTime.Now;
                db.UpdateTime(current);
            }
            //Update Updated Time for Conservation

            return(Ok(new HTTPMessageDTO {
                Status = WsConstant.HttpMessageType.SUCCESS
            }));
        }
Esempio n. 2
0
        public IHttpActionResult AddConservation(ConservationBasicInfoDTO newConservation)
        {
            int          receiverId  = 0;
            int          CurrentUser = 0;
            Conversation returnedConservation;

            try {
                using (var db = new UserDAL())
                {
                    CurrentUser = db.GetUserByUserNameOrEmail(User.Identity.Name).UserID;
                    receiverId  = db.GetUserByUserNameOrEmail(newConservation.ReceiverName).UserID;
                }
                //Add conservation
                var conservation = new Conversation
                {
                    CreatorId      = CurrentUser,
                    ReceiverId     = receiverId,
                    Title          = newConservation.Title,
                    UpdatedTime    = DateTime.Now,
                    CreatedDate    = DateTime.Now,
                    Status         = true,
                    IsCreatorRead  = true,
                    IsReceiverRead = false,
                };
                using (var db = new ConservationDAL())
                {
                    returnedConservation = db.AddNewConservation(conservation);
                }
                //Add First Message of Conservation
                var message = new Message
                {
                    UserId         = CurrentUser,
                    ConservationId = returnedConservation.ConservationId,
                    Content        = newConservation.Content,
                    CreatedDate    = DateTime.Now,
                    Status         = true
                };
                using (var db = new ConservationDAL())
                {
                    db.AddNewMessage(message);
                }
            }
            catch (Exception)
            {
                return(Redirect("/#/Error"));
            }
            return(Ok(new HTTPMessageDTO {
                Status = WsConstant.HttpMessageType.SUCCESS
            }));
        }