public ActionResult AdminLoginValidate(FormCollection formCollection) { try { //string userId = formCollection["UserId"]; string psswrd = formCollection["Password"]; if (psswrd.Equals("adminLogin")) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { ViewData["grouplist"] = db.EventGroupNames.ToList(); ViewData["EventGroupTitle"] = db.EventGroupTitles.ToList(); ViewData["EventTypeOne"] = db.EventTypeOnes.ToList(); } return View("AdminPanel"); } else { return Content("There is problem while working on filter. Please try again."); } } catch (Exception ex) { return Content("There is problem while working on filter. Please try again."); } }
// GET: /Event/Create public ActionResult Create() { List<SelectListItem> liEventGroups = new List<SelectListItem>(); List<SelectListItem> liEventTypes = new List<SelectListItem>(); List<SelectListItem> liEventGroupNames = new List<SelectListItem>(); using (EventOrganizerEntities db = new EventOrganizerEntities()) { if (db.EventGroupTitles.Count() > 0) { foreach (EventGroupTitle group in db.EventGroupTitles.Where(x => !x.IsDeleted).OrderBy(x => x.Title).ToList()) { liEventGroups.Add(new SelectListItem { Text = group.Title, Value = group.Title }); } } if (db.EventGroupNames.Count() > 0) { foreach (EventGroupName group in db.EventGroupNames.Where(x => !x.IsDeleted).OrderBy(x => x.GroupName).ToList()) { liEventGroupNames.Add(new SelectListItem { Text = group.GroupName, Value = group.GroupName }); } } if (db.EventTypeOnes.Count() > 0) { foreach (EventTypeOne typ in db.EventTypeOnes.Where(x => !x.IsDeleted).OrderBy(x => x.EventTypeName).ToList()) { liEventTypes.Add(new SelectListItem { Text = typ.EventTypeName, Value = typ.EventTypeName }); } } } ViewData["typeList"] = liEventTypes; ViewData["groupList"] = liEventGroups; ViewData["groupNameList"] = liEventGroupNames; return View(); }
// GET api/Event public IQueryable<CalendarEvent> GetCalendarEvents() { using (EventOrganizerEntities eventOrganizerEntities = new EventOrganizerEntities()) { return eventOrganizerEntities.CalendarEvents; } }
public IHttpActionResult GetCalendarEvent(int id) { CalendarEvent calendarevent; using (EventOrganizerEntities eventOrganizerEntities = new EventOrganizerEntities()) { calendarevent = eventOrganizerEntities.CalendarEvents.Find(id); } if (calendarevent == null) { return NotFound(); } return Ok(calendarevent); }
public IHttpActionResult PostCalendarEvent(CalendarEvent calendarevent) { if (!ModelState.IsValid) { return BadRequest(ModelState); } using (EventOrganizerEntities eventOrganizerEntities = new EventOrganizerEntities()) { eventOrganizerEntities.CalendarEvents.Add(calendarevent); eventOrganizerEntities.SaveChanges(); } return CreatedAtRoute("DefaultApi", new { id = calendarevent.Id }, calendarevent); }
public IHttpActionResult DeleteCalendarEvent(int id) { CalendarEvent calendarevent; using (EventOrganizerEntities eventOrganizerEntities = new EventOrganizerEntities()) { calendarevent = eventOrganizerEntities.CalendarEvents.Find(id); if (calendarevent == null) { return NotFound(); } else { eventOrganizerEntities.CalendarEvents.Remove(calendarevent); eventOrganizerEntities.SaveChanges(); } } return Ok(calendarevent); }
private bool CalendarEventExists(int id) { using (EventOrganizerEntities eventOrganizerEntities = new EventOrganizerEntities()) { return eventOrganizerEntities.CalendarEvents.Count(e => e.Id == id) > 0; } }
public ActionResult DeleteConfirmed(int id) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { CalendarEvent calendarevent = db.CalendarEvents.Find(id); db.CalendarEvents.Remove(calendarevent); db.SaveChanges(); } return RedirectToAction("Index"); }
private bool DeleteTitleType(int Id) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { var item = db.EventTypeOnes.Where(x => x.Id == Id).FirstOrDefault(); if (item != null) { item.IsDeleted = true; db.SaveChanges(); } } return false; }
public ActionResult Create([Bind(Include = "Id,EventTitle,Abstract,EventDescription,StartDate,EndDate,Location,Url,Price,EventGroupTitle,EventGroupName,EventTypeOne")] CalendarEvent calendarevent) { if (ModelState.IsValid) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { try { calendarevent.CreatedDateTime = DateTime.UtcNow; calendarevent.LastUpdateDateTime = DateTime.UtcNow; calendarevent.IsDeleted = false; db.CalendarEvents.Add(calendarevent); db.SaveChanges(); return Content("Event has been created successfully!"); } catch (Exception ex) { return Content("There is problem in saving the event. Please try again."); } } } else { return View(calendarevent); } }
// GET: /Event/ public ActionResult Index() { using (EventOrganizerEntities db = new EventOrganizerEntities()) { return View(db.CalendarEvents.ToList()); } }
/// <summary> /// ics file download /// </summary> /// <param name="guid"></param> private void Download(string guid) { if (!string.IsNullOrEmpty(guid)) { List<CalendarEvent> calendarEvents; using (EventOrganizerEntities db = new EventOrganizerEntities()) { calendarEvents = db.usp_GetEventsByGuid(Extensions.DecodeFrom64(guid)).ToList(); } string fileName = Guid.NewGuid().ToString() + ".ics"; Response.Write("BEGIN:VCALENDAR" + Environment.NewLine); Response.Write("VERSION:2.0" + Environment.NewLine); Response.Write("PRODID: -//ScheduleOnce//EN" + Environment.NewLine); Response.Write("METHOD:PUBLISH" + Environment.NewLine); Response.AddHeader("content-disposition", "attachment; filename=" + fileName); StringBuilder eventInICSFormat = new StringBuilder(); foreach (CalendarEvent calEvent in calendarEvents) { eventInICSFormat.Append("BEGIN:VEVENT" + Environment.NewLine); eventInICSFormat.Append("DTEND:" + (calEvent.EndDate.ToString("s").Replace("-", "").Replace(":", "")) + Environment.NewLine); eventInICSFormat.Append("DTSTART:" + calEvent.StartDate.ToString("s").Replace("-", "").Replace(":", "") + Environment.NewLine); StringBuilder eventDescription = new StringBuilder(); if (!string.IsNullOrWhiteSpace(calEvent.Abstract)) { eventDescription.Append(calEvent.Abstract + "\\n"); } if (!string.IsNullOrWhiteSpace(calEvent.EventDescription)) { eventDescription.Append("Event Details : " + calEvent.EventDescription.Replace(Environment.NewLine, "\\n") + "\\n"); } if (!string.IsNullOrWhiteSpace(calEvent.Url)) { eventDescription.Append("Url : " + calEvent.Url + "\\n"); } if (calEvent.Price.HasValue) { eventDescription.Append("Price : " + calEvent.Price.Value.ToString()); } eventInICSFormat.Append("DESCRIPTION:" + eventDescription.ToString() + Environment.NewLine); eventInICSFormat.Append("LOCATION:" + calEvent.Location + Environment.NewLine); eventInICSFormat.Append("PRIORITY:5" + Environment.NewLine); eventInICSFormat.Append("SEQUENCE:0" + Environment.NewLine); eventInICSFormat.Append("SUMMARY;LANGUAGE=en-us:" + calEvent.EventTitle + Environment.NewLine); eventInICSFormat.Append("TRANSP:OPAQUE" + Environment.NewLine); eventInICSFormat.Append(string.Format("UID:{0}", Guid.NewGuid().ToString().ToUpper()) + Environment.NewLine); eventInICSFormat.Append("BEGIN:VALARM" + Environment.NewLine); eventInICSFormat.Append("TRIGGER:-PT15M" + Environment.NewLine); eventInICSFormat.Append("ACTION:DISPLAY" + Environment.NewLine); eventInICSFormat.Append("DESCRIPTION:Reminder" + Environment.NewLine); eventInICSFormat.Append("END:VALARM" + Environment.NewLine); eventInICSFormat.Append("END:VEVENT" + Environment.NewLine); } eventInICSFormat.Append("END:VCALENDAR" + Environment.NewLine); Response.Write(eventInICSFormat); Response.End(); } }
private void AddTitleType(string name) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { var item = db.EventTypeOnes.Where(x => x.EventTypeName == name).FirstOrDefault(); if (item == null) { EventTypeOne obj = new EventTypeOne(); obj.EventTypeName = name; obj.IsDeleted = false; obj.CreatedDateTime = DateTime.UtcNow; obj.LastUpdateDateTime = DateTime.UtcNow; db.EventTypeOnes.Add(obj); db.SaveChanges(); } } }
public ActionResult EventFilter(FormCollection formCollection) { try { string guid = Guid.NewGuid().ToString(); string filterValue = CreateFilterXml(formCollection); using (EventOrganizerEntities db = new EventOrganizerEntities()) { ObjectParameter guidOutput = new ObjectParameter("Guid", typeof(string)); guidOutput.Value = guid; db.usp_AddEventFilter(filterValue, guidOutput); guid = Convert.ToString(guidOutput.Value); } using (EventOrganizerEntities db = new EventOrganizerEntities()) { List<CalendarEvent> calendarEvents = db.usp_GetEventsByGuid(guid).ToList(); if (calendarEvents == null || calendarEvents.Count == 0) return Content("No event is associated with your filter criteria. Please try different filter settings.,0"); } //guid changed to base 64 encrypted string guid = Extensions.EncodeTo64(guid); ViewData["eventUrl"] = HttpContext.Request.Url.ToString().Replace("EventFilter", "DownloadEvent/") + guid; return Content("Your filter has been applied, please download the calendar event!," + HttpContext.Request.Url.ToString().Replace("EventFilter", "DownloadEvent/") + guid); } catch (Exception) { return Content("There is problem while working on filter. Please try again."); } }
private void EditGroupTitle(string groupTitle, int id) { if (!string.IsNullOrEmpty(groupTitle)) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { var item = db.EventGroupTitles.Where(x => x.Id == id).FirstOrDefault(); db.Usp_UpdateCalendarEvents(groupTitle, item.Title, (int)Purpose.EditGroupTitle); if (item != null) { item.Title = groupTitle; db.SaveChanges(); } } } }
private void EditTitleType(string titleType, int id) { if (!string.IsNullOrEmpty(titleType)) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { var item = db.EventTypeOnes.Where(x => x.Id == id).FirstOrDefault(); db.Usp_UpdateCalendarEvents(titleType, item.EventTypeName, (int)Purpose.EditType); if (item != null) { item.EventTypeName = titleType; db.SaveChanges(); } } } }
public ActionResult Create([Bind(Include = "Id,EventTitle,Abstract,EventDescription,StartDate,EndDate,Location,Url,Price,EventGroupTitle,EventGroupName,EventTypeOne")] CalendarEvent calendarevent) { if (ModelState.IsValid) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { try { calendarevent.CreatedDateTime = DateTime.UtcNow; calendarevent.LastUpdateDateTime = DateTime.UtcNow; calendarevent.IsDeleted = false; db.CalendarEvents.Add(calendarevent); db.SaveChanges(); return Content("Event has been created successfully!"); } catch (DbEntityValidationException e) { StringBuilder sb = new StringBuilder(); foreach (var eve in e.EntityValidationErrors) { sb.Append(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State)); foreach (var ve in eve.ValidationErrors) { sb.Append(string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage)); } } return Content(sb.ToString()); } catch (Exception ex) { //return Content(ex.Message.ToString()); return Content("There is problem in saving the event. Please try again."); } } } else { return View(calendarevent); } }
public ActionResult GetDropDownMenuItems(string id) { var grouptitle = id; List<SelectListItem> liEventGroupNames = new List<SelectListItem>(); using (EventOrganizerEntities db = new EventOrganizerEntities()) { var allgroupnames = db.EventGroupNames.Where(x => x.GroupTitle == grouptitle).OrderBy(x => x.GroupTitle).ToList(); if(allgroupnames.Count > 0) { foreach (EventGroupName group in allgroupnames) { liEventGroupNames.Add(new SelectListItem { Text = group.GroupName, Value = group.GroupName }); } } return Json(liEventGroupNames); } return Json("{1 : 1}"); }
public string SaveChanges(int id, string value, Purpose purpose) { try { switch (purpose) { case Purpose.DeleteGroupName: DeleteGroupName(id); break; case Purpose.DeleteGroupTitle: DeleteGroupTitle(id); break; case Purpose.DeleteTYpe: DeleteTitleType(id); break; case Purpose.EditGroupName: EditGroupName(value, id); break; case Purpose.EditGroupTitle: EditGroupTitle(value, id); break; case Purpose.EditType: EditTitleType(value, id); break; case Purpose.AddGroupName: AddGroupName(value); break; case Purpose.AddGroupTitle: AddGroupTitle(value); break; case Purpose.AddTitleType: AddTitleType(value); break; } using (EventOrganizerEntities db = new EventOrganizerEntities()) { ViewData["grouplist"] = db.EventGroupNames.ToList(); ViewData["EventGroupTitle"] = db.EventGroupTitles.ToList(); ViewData["EventTypeOne"] = db.EventTypeOnes.ToList(); } return "true"; } catch { return "false"; } }
// GET: /Event/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } using (EventOrganizerEntities db = new EventOrganizerEntities()) { CalendarEvent calendarevent = db.CalendarEvents.Find(id); if (calendarevent == null) { return HttpNotFound(); } return View(calendarevent); } }
public ActionResult Edit([Bind(Include = "Id,EventTitle,Abstract,EventDescription,StartDate,EndDate,Location,Url,Price,EventGroupTitle,EventGroupName,EventTypeOne,CreatedDateTime,LastUpdateDateTime,IsDeleted")] CalendarEvent calendarevent) { if (ModelState.IsValid) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { db.Entry(calendarevent).State = EntityState.Modified; db.SaveChanges(); } return RedirectToAction("Index"); } return View(calendarevent); }
// PUT api/Event/5 public IHttpActionResult PutCalendarEvent(int id, CalendarEvent calendarevent) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != calendarevent.Id) { return BadRequest(); } using (EventOrganizerEntities eventOrganizerEntities = new EventOrganizerEntities()) { try { eventOrganizerEntities.Entry(calendarevent).State = EntityState.Modified; eventOrganizerEntities.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CalendarEventExists(id)) { return NotFound(); } else { throw; } } } return StatusCode(HttpStatusCode.NoContent); }
private void AddGroupName(string name) { if (!string.IsNullOrEmpty(name)) { using (EventOrganizerEntities db = new EventOrganizerEntities()) { var item = db.EventGroupNames.Where(x => x.GroupName == name).FirstOrDefault(); if (item == null) { EventGroupName obj = new EventGroupName(); obj.GroupName = name; obj.IsDeleted = false; obj.CreatedDateTime = DateTime.UtcNow; obj.LastUpdateDateTime = DateTime.UtcNow; db.EventGroupNames.Add(obj); db.SaveChanges(); } } } }