Exemplo n.º 1
0
        /// <summary>
        /// Create a new note
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult Create(NoteViewModel model)
        {
            //remove Id from modelstate if tehre. 
            ModelState.Remove("Id"); 
            ModelState.Remove("EventDate");
            ModelState.Remove("CreatedBy");
            if (ModelState.IsValid)
            {
                var note = new Note
                               {
                                   CreatedBy = OrgUser.ToSimpleUser(),
                                   EventDate = DateTime.Now,
                                   ConsolidatedCompletionDate = DateTime.Now,
                                   Comment = model.Comment,
                                   Id = IlluminateDatabase.GenerateId<Note>()
                               };

                using (var orgSession = OrgStore.OpenSession())
                {
                    orgSession.Store(note);
                    orgSession.SaveChanges();

                    return JsonSuccess(note.ToTimelineItems(), "Note created");
                }
            }
            return JsonError("Invalid data");
        }
Exemplo n.º 2
0
        // POST api/mailgun
        public void Post(FormDataCollection formData)
        {
            var email = ToIncomingEmail(formData);
            //TODO - validate email is actually from mailgun by using security
            //work out which organisation it is for

            //TODO - do this in a better way - don't want to search through each org db if possible
            foreach (var orgStore in WebApiApplication.DataBase.GetAllOrgStores())
            {
                using (var session = orgStore.OpenSession())
                {
                    var matchedUser =
                        session.Query<User>().FirstOrDefault(user => user.EmailAddress == email.Sender);
                    if (matchedUser != null)
                    {
                        var note = new Note
                                       {
                                           Id = IlluminateDatabase.GenerateId<Note>(),
                                           Comment = email.ToString(),
                                           CreatedBy = matchedUser.ToSimpleUser(),
                                           EventDate = DateTime.Now,
                                           ConsolidatedCompletionDate = DateTime.Now
                                       };
                        session.Store(note);
                        session.SaveChanges();
                    }
                }
            }
            
           //TODO - remove this once its all working
            using (var session= WebApiApplication.DataBase.MasterStore.OpenSession())
            {
                session.Store(email);
                session.SaveChanges();
            }

            
        }