public ActionResult Messages(string senderid)
        {
            string userid = User.Identity.GetUserId();

            ViewBag.userid = userid;


            string logged_in_user_role;

            if (User.IsInRole("Owner"))
            {
                logged_in_user_role = "Owner";
            }
            else
            {
                logged_in_user_role = "Traveler";
            }

            MessageFormViewModel messagemodel = new MessageFormViewModel()
            {
                receiverid = userid,
                userid     = senderid
            };

            ViewBag.UserRole = logged_in_user_role;

            return(View(messagemodel));
        }
Exemplo n.º 2
0
        public ActionResult Save(MessageFormViewModel viewModel)
        {
            //viewModel.Message = _context.Messages.FirstOrDefault(g => g.Id == viewModel.Message.Id); //GIVES ERROR

            /*viewModel.Message = _context.Messages.First(); //WORKS BUT DOESNT SUBMIT
             * if (!ModelState.IsValid)
             * {
             *  viewModel = new MessageFormViewModel
             *  {
             *      Message = viewModel.Message
             *  };
             *  return View("New", viewModel);
             * }
             * if (viewModel.Message.Id == 0)
             *  _context.Messages.Add(viewModel.Message);
             * else
             * {
             *  var messageInDb = _context.Messages.Single(messageT => messageT.Id == viewModel.Message.Id);
             *  messageInDb.content = viewModel.Message.content;
             * }*/
            _context.Messages.Add(viewModel.Message);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Messages"));
        }
        public async Task <IActionResult> Add(MessageFormViewModel model)
        {
            var senderId = this.userManager.GetUserId(this.User);

            await this.service.AddMessage(model.Description, senderId);

            return(RedirectToAction(nameof(HomeController.Index), WebConstants.HomeControllerName));
        }
Exemplo n.º 4
0
        public ActionResult New()
        {
            var message   = new Message();
            var ViewModel = new MessageFormViewModel
            {
                Message = message
            };

            return(View(ViewModel));
        }
Exemplo n.º 5
0
        public ActionResult Create()
        {
            var viewModel = new MessageFormViewModel
            {
                Genres  = _context.Genres.ToList(),
                Heading = "Add a Message"
            };

            return(View("MessageForm", viewModel));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> SendMessage(MessageFormViewModel viewModel, string roomId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(await messenger.Send(viewModel.Text, HttpContext.User.Identity.Name, roomId) != null
                ? (IActionResult)Ok()
                : BadRequest());
        }
        public IActionResult Contacts(MessageFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            this.messages.Create(model.Name,
                                 model.Email,
                                 model.Phone,
                                 model.Subject,
                                 model.Content);

            TempData["SuccessMessage"] = "Thank You for your message!";

            return(RedirectToAction(nameof(Contacts)));
        }
        public ActionResult SaveMessage(MessageFormViewModel messageFormViewModel)
        {
            var UserId = User.Identity.GetUserId();

            Message message = new Message()
            {
                Body              = messageFormViewModel.body,
                DateOfMessage     = messageFormViewModel.dateofmessage,
                OwnerOrTraveler   = "Traveler",
                ApplicationUserId = UserId,
                ReceiverId        = messageFormViewModel.receiverid,
                PropertyId        = messageFormViewModel.propertyid
            };

            _context.Messages.Add(message);
            _context.SaveChanges();
            return(View("CreateMessage"));
        }
Exemplo n.º 9
0
        public ActionResult Add()
        {
            if (!Init(User))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!_permission.Contains(PermissionEnum.SEND_EMAIL))
            {
                return(RedirectToAction("Menu", "Home"));
            }

            MessageFormViewModel model = new MessageFormViewModel();

            model.UserName   = GetEmail();
            model.Categories = GetCategories();
            return(View("_Form", model));
        }
Exemplo n.º 10
0
        public ActionResult Edit(int id)
        {
            var userId  = User.Identity.GetUserId();
            var message = _context.Messages.FirstOrDefault(g => g.Id == id && g.ArtistId == userId);

            var viewModel = new MessageFormViewModel
            {
                Heading = "Edit a Message",
                Id      = message.Id,
                Genres  = _context.Genres.ToList(),
                Date    = message.DateTime.ToString("d MMM yyyy"),
                Time    = message.DateTime.ToString("HH mm"),
                Genre   = message.GenreId,
                Message = message.Venue
            };

            return(View("MessageForm", viewModel));
        }
        public ActionResult CreateMessage(string owner)
        {
            var prop   = _context.Properties.Where(a => a.ApplicationUserId == owner).FirstOrDefault();
            var propid = prop.Id;



            MessageFormViewModel messageformviewmodel = new MessageFormViewModel()
            {
                userid        = User.Identity.GetUserId(),
                dateofmessage = DateTime.Now,
                receiverid    = owner,
                propertyid    = propid
            };



            return(View(messageformviewmodel));
        }
Exemplo n.º 12
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Message message = _context.Messages.Find(id);

            if (message == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new MessageFormViewModel
            {
                Message = message
            };

            return(View("Delete", viewModel));
        }
Exemplo n.º 13
0
        public ActionResult Update(MessageFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();
                return(View("MessageForm", viewModel));
            }

            var userId  = User.Identity.GetUserId();
            var message = _context.Messages.FirstOrDefault(g => g.Id == viewModel.Id && g.ArtistId == userId);

            message.Venue    = viewModel.Message;
            message.DateTime = viewModel.GetDateTime();
            message.GenreId  = viewModel.Genre;


            _context.SaveChanges();

            return(RedirectToAction("Mine", "Messages"));
        }
Exemplo n.º 14
0
        public ActionResult Create(MessageFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();
                return(View("MessageForm", viewModel));
            }

            var message = new Message
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = viewModel.GetDateTime(),
                GenreId  = viewModel.Genre,
                Venue    = viewModel.Message
            };

            _context.Messages.Add(message);
            _context.SaveChanges();

            return(RedirectToAction("Mine", "Messages"));
        }
Exemplo n.º 15
0
        public async Task <ActionResult> Add(MessageFormViewModel model)
        {
            if (!Init(User))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!_permission.Contains(PermissionEnum.SEND_EMAIL))
            {
                return(RedirectToAction("Menu", "Home"));
            }

            if (string.IsNullOrEmpty(model.Title))
            {
                ModelState.AddModelError("", "Należy podać tytuł wiadomości");
            }

            if (string.IsNullOrEmpty(model.Content))
            {
                ModelState.AddModelError("", "Należy podać treść wiadomości");
            }

            int categoryId;

            int.TryParse(model.Category, out categoryId);
            if (_categoryRepository.GetById(categoryId) == null)
            {
                ModelState.AddModelError("", "Nieprawidłowa kategoria wiadomości");
            }

            if (ModelState.IsValid)
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    MessageDTO messageDTO = new MessageDTO()
                    {
                        Title      = model.Title,
                        Content    = model.Content,
                        CategoryId = categoryId,
                        UserId     = _administrator.Id
                    };

                    httpClient.BaseAddress = new Uri(Configuration.API_ADDRESS);

                    StringContent       content  = new StringContent(JsonConvert.SerializeObject(messageDTO), Encoding.UTF8, "application/json");
                    HttpResponseMessage response = await httpClient.PostAsync("message/", content);

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        response = await httpClient.PostAsync("message/", content);
                    }

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string count = await response.Content.ReadAsStringAsync();

                        Session[Configuration.Information] = $"Wiadomość została wysłana do {count} użytkowników";
                        return(RedirectToAction("Menu", "Home"));
                    }
                    else
                    {
                        Session[Configuration.Information] = "Wystąpił błąd. Proszę spróbować później.";
                        return(RedirectToAction("Menu", "Home"));
                    }
                }
            }

            model.HasError   = true;
            model.UserName   = GetEmail();
            model.Categories = GetCategories();
            return(View("_Form", model));
        }