public JsonResult SendMessage(string text, int sender, int receiver)
        {
            /*
             * if (user == null)
             * {
             *  return Json(new { success = false, reason = "The user could not be found." });
             * }
             */
            Messages message = new Messages();

            message.Text     = text;
            message.Sender   = sender;
            message.Receiver = receiver;
            try
            {
                _context.Messages.AddAsync(message).Wait();
                _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }



            return(Json(new { success = true }));
        }
        public async Task <IActionResult> Create([Bind("Name,Description,Department,Number,Semester,Year,StatusId,DueDate")] CourseInstance courseInstance, string[] instructors)
        {
            if (ModelState.IsValid)
            {
                _context.Add(courseInstance);
                if (instructors != null)
                {
                    foreach (string instructor in instructors)
                    {
                        UserLocator instr = _context.UserLocator.Where(u => u.UserLoginEmail == instructor).FirstOrDefault();
                        if (instr != null)
                        {
                            _context.Instructors.Add(new Instructors()
                            {
                                CourseInstance = courseInstance, User = instr
                            });
                        }
                    }
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseInstanceId"] = new SelectList(_context.CourseInstance, "CourseInstanceId", "Department", courseInstance.CourseInstanceId);
            return(View(courseInstance));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Loid,Name,Description,CourseInstanceId")] LearningOutcomes learningOutcomes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(learningOutcomes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseInstanceId"] = new SelectList(_context.CourseInstance, "CourseInstanceId", "Department", learningOutcomes.CourseInstanceId);
            return(View(learningOutcomes));
        }