private int SaveEvent(EventModels.NewEvent Model) { int siteCoID = siteusercompanyid; var isNewEvent = (Model.EventID ?? 0) == 0; ActivitiesEvents newEvent = new ActivitiesEvents() { EventID = Model.EventID ?? 0, SiteCoID = siteusercompanyid, SiteUserID = Model.OwnerID ?? siteuserid, EventName = Model.Event ?? "", ProjectID = Model.JobID ?? 0, StatusID = Model.StatusID, EventDate = Model.Date, EventTime = Model.Date.HasValue ? Model.Date.Value.TimeOfDay : new TimeSpan(), EventHours = Model.Duration ?? 1, AllDay = Model.Duration >= 24, Notes = Model.Notes ?? "", AcctTaskID = "", RecurrenceRule = "" }; BOL.Repository.CommonRepository repo = new BOL.Repository.CommonRepository(); int eventID = Model.EventID ?? 0; using (TransactionScope scope = new TransactionScope()) { eventID = repo.SaveEvent(newEvent); if (isNewEvent) { repo.AddEventInvitees(eventID, ExtractInviteeIdsData(Model.InviteeIds)); } else { repo.UpdateEventInvitees(eventID, ExtractInviteeIdsData(Model.InviteeIds)); } scope.Complete(); } if (eventID > 0) { return(eventID); } else { return(0); } }
public ActionResult Edit(int?id, int?contactid, int?projectid) { if (projectid.HasValue) { BOL.Repository.CommonRepository repo = new BOL.Repository.CommonRepository(); contactid = repo.GetContactIdByProjectID(projectid.Value); } var siteUsers = db.SiteUsers.Where(p => p.SiteCoID == siteusercompanyid).OrderBy(p => p.UserDisplayName); ViewBag.Owners = new SelectList(siteUsers, "SiteUserID", "UserDisplayName", siteuserid); ViewBag.Jobs = new SelectList(db.GetJobsByContactID_WithLockFalse(contactid), "ViewID", "Project"); ViewBag.Status = new SelectList(repo.GetActivityStatus(siteusercompanyid), "StatusID", "StatusName"); ViewBag.IsFieldsReadOnly = true; var invitees = GetEventInvitees(id ?? 0); ViewBag.Invitees = new MultiSelectList(GetUsersForEventInvitation(siteusercompanyid), "Item1", "Item2", invitees); EventModels.NewEvent model = new EventModels.NewEvent(); ActivitiesEvents _event = db.ActivitiesEvents.Where(p => p.EventID == (id ?? 0)).FirstOrDefault(); if (_event != null) { model = new EventModels.NewEvent() { EventID = _event.EventID, Date = _event.EventDate.HasValue ? _event.EventDate.Value.Add(_event.EventTime ?? new TimeSpan()) : new Nullable <DateTime>(), Duration = _event.EventHours, Event = _event.EventName ?? "", JobID = _event.ProjectID, Notes = _event.Notes, OwnerID = _event.SiteUserID, StatusID = _event.StatusID, InviteeIds = invitees }; } ViewBag.SelectedContactID = contactid; return(View("_Edit", model)); }