Пример #1
0
        public async Task <ActionResult <Note> > PostNote(PostNoteModel newNote)
        {
            var note = new Note {
                Description  = newNote.Description,
                CategoryID   = newNote.CategoryID,
                IntentedDate = newNote.IntentedDate
            };

            _context.Notes.Add(note);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetNote", new { id = note.NoteID }, note));
        }
Пример #2
0
        public async Task <IActionResult> Note(PostNoteModel model)
        {
            var user = await userManager.GetUserAsync(User);

            if (user == null ||
                !(await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.VolunteerCaptain.ToString()) ||
                  await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.BusDriver.ToString()) ||
                  await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())))
            {
                return(Utilities.ErrorJson("Not authorized."));
            }

            List <String> missingParameters = new List <String>();

            if (model.Author.Equals(""))
            {
                missingParameters.Add("author name");
            }

            if (model.ChildId == 0)
            {
                missingParameters.Add("child id");
            }

            if (model.Content.Equals(""))
            {
                missingParameters.Add("content");
            }

            if (model.Priority.Equals(""))
            {
                missingParameters.Add("priority");
            }

            if (model.Date.Equals(""))
            {
                missingParameters.Add("date");
            }

            if (missingParameters.Count > 0)
            {
                Utilities.GenerateMissingInputMessage(missingParameters);
            }

            try
            {
                ChildRepository repo = new ChildRepository(configModel.ConnectionString);
                // Email which class the child is in, which bus they are in, the priority level, and who wrote this note
                String childName = repo.GetName(model.ChildId);
                String className = repo.GetClassName(model.ChildId);
                String busName   = repo.GetBusName(model.ChildId);

                String message = "A new note has been added about " + childName + " with the priority level " +
                                 model.Priority + ". The child is in the class " + className + " and on the bus " + busName + ". The" +
                                 " note was written by " + model.Author + ".";

                String subject = "New note: " + childName + " in class " + className + " - " + model.Priority + ".";


                await EmailHelpers.SendEmail("*****@*****.**", subject, message, configModel.EmailOptions);

                repo.AddNote(model.Author, model.ChildId, model.Content, model.Date);

                return(new JsonResult(new
                {
                    Error = ""
                }));
            }
            catch (Exception exc)
            {
                return(new JsonResult(new
                {
                    Error = exc.Message
                }));
            }
        }