Esempio n. 1
0
 public int AddUpdateEvent(EventViewModel eventViewModel)
 {
     if (eventViewModel.Id == 0)
         return AddEvent(eventViewModel);
     else
         return UpdateEvent(eventViewModel);
 }
Esempio n. 2
0
 public int AddEvent(EventViewModel eventViewModel)
 {
     var entity = new Event();
     entity.Title = eventViewModel.Title;
     entity.ShortDescription = eventViewModel.ShortDescription;
     entity.LongDescription = eventViewModel.LongDescription;
     entity.StartDate = Convert.ToDateTime(eventViewModel.StartDate);
     entity.EndDate = Convert.ToDateTime(eventViewModel.EndDate);
     entity.RecurrenceRule = eventViewModel.RecurrenceRule;
     entity.ReminderMode = (ReminderType)Enum.Parse(typeof(ReminderType), eventViewModel.ReminderMode.ToString().Replace(" ","_"));
     entity.CreatedOn = System.DateTime.Now;
     entity.LastModifiedOn = System.DateTime.Now;
     var x = db.Events.Add(entity);
     db.SaveChanges();
     return x.Id;
 }
Esempio n. 3
0
 public void SendEmail(EventViewModel eventDetails)
 {
     string body = File.ReadAllText(HttpContext.Current.Server.MapPath("~/Partials/Emails/EventNotificationTemplate.html"));
     body = body.Replace("{UserName}", _toPerson);
     body = body.Replace("{EventTitle}", eventDetails.Title);
     body = body.Replace("{ShortDescription}", eventDetails.ShortDescription);
     body = body.Replace("{TodaysDate}", "" + GetNZLocalTime());
     body = body.Replace("{LongDescription}", eventDetails.LongDescription);
     string subject = "" + eventDetails.Title;
     dynamic sg = new SendGridAPIClient(_emailApiKey);
     Email from = new Email(_fromEmail, _fromPerson);
     Email to = new Email(_toEmail);
     Content content = new Content("text/html", body);
     Mail mail = new Mail(from, subject, to, content);
     dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
 }
Esempio n. 4
0
        public IHttpActionResult PostEvent(EventViewModel eventViewModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            try
            {
                var r = _eventsService.AddUpdateEvent(eventViewModel);

                //return
                //db.Events.Add(@event);
                //db.SaveChanges();

                return CreatedAtRoute("DefaultApi", new { id = r }, eventViewModel);
            }
            catch(Exception e)
            {
                return BadRequest(""+e.InnerException);
            }
        }
Esempio n. 5
0
 public int UpdateEvent(EventViewModel eventViewModel)
 {
     var entity = db.Events.SingleOrDefault(b => b.Id == eventViewModel.Id);
     if (entity != null)
     {
         entity.Title = eventViewModel.Title;
         entity.ShortDescription = eventViewModel.ShortDescription;
         entity.LongDescription = eventViewModel.LongDescription;
         entity.StartDate = Convert.ToDateTime(eventViewModel.StartDate);
         entity.EndDate = Convert.ToDateTime(eventViewModel.EndDate);
         entity.RecurrenceRule = eventViewModel.RecurrenceRule;
         entity.ReminderMode = (ReminderType)Enum.Parse(typeof(ReminderType), eventViewModel.ReminderMode.ToString().Replace(" ", "_"));
         entity.LastModifiedOn = System.DateTime.Now;
         db.SaveChanges();
     }
     return entity.Id;
 }
Esempio n. 6
0
        public IHttpActionResult PutEvent(int id, EventViewModel @event)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != @event.Id)
            {
                return BadRequest();
            }

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                var r = _eventsService.AddUpdateEvent(@event);
                return Ok(r);
            }
            catch (Exception e)
            {
                return StatusCode(HttpStatusCode.NoContent);
            }
        }