public bool CreateNewEvent(string Title, string NewEventDate, string NewEventAddress, string NewEventDescription, string NewEventSTime, string NewEventETime, string NewEventDuration, int EventSymbol) { try { Entities ent = new Entities(); EventCalendar evt = new EventCalendar(); evt.UserID = HttpContext.Current.User.Identity.GetUserId<int>(); evt.Title = Title; evt.Address = NewEventAddress; evt.DateTimeScheduled = DateTime.Parse(NewEventDate); evt.Description = NewEventDescription; evt.EndDay = evt.DateTimeScheduled; evt.StatusENUM = EventSymbol; evt.IsActive = true; ent.EventCalendars.Add(evt); ent.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } return false; } return true; }
public void UpdateEvents(int id, string NewEventStart, string NewEventEnd) { using (Entities ent = new Entities()) { var rec = ent.EventCalendars.FirstOrDefault(s => s.ID == id); if (rec != null) { DateTime DateTimeStart = DateTime.Parse(NewEventStart, null, DateTimeStyles.RoundtripKind).ToLocalTime(); // and convert offset to localtime rec.DateTimeScheduled = DateTimeStart; if (!String.IsNullOrEmpty(NewEventEnd)) { TimeSpan span = DateTime.Parse(NewEventEnd, null, DateTimeStyles.RoundtripKind).ToLocalTime() - DateTimeStart; rec.EndDay = DateTime.Parse(NewEventEnd, null, DateTimeStyles.RoundtripKind).ToLocalTime(); } ent.SaveChanges(); } } }