public ActionResult DeleteConfirmed(long id) { tblActivity tblactivity = db.tblActivities.Find(id); db.tblActivities.Remove(tblactivity); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "activityId,name,locationId,typeId,description,createdBy,createdDate,updatedBy,updatedDate")] tblActivity tblactivity) { if (ModelState.IsValid) { db.Entry(tblactivity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.locationId = new SelectList(db.tblLocations, "locId", "name", tblactivity.locationId); ViewBag.typeId = new SelectList(db.tblMediumPrepTypes, "typeId", "typename", tblactivity.typeId); return(View(tblactivity)); }
// GET: /Activity/Details/5 public ActionResult Details(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblActivity tblactivity = db.tblActivities.Find(id); if (tblactivity == null) { return(HttpNotFound()); } return(View(tblactivity)); }
// GET: /Activity/Edit/5 public ActionResult Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblActivity tblactivity = db.tblActivities.Find(id); if (tblactivity == null) { return(HttpNotFound()); } ViewBag.locationId = new SelectList(db.tblLocations, "locId", "name", tblactivity.locationId); ViewBag.typeId = new SelectList(db.tblMediumPrepTypes, "typeId", "typename", tblactivity.typeId); return(View(tblactivity)); }
/// <summary> /// Function to get activity by id /// </summary> /// <returns>ActivityVM</returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/03/2015 /// </devdoc> public static ActivityVM GetActivityById(int id) { StringBuilder traceLog = null; using (LinksMediaContext dataContext = new LinksMediaContext()) { traceLog = new StringBuilder(); try { ///Get challenge detail by challenge traceLog.AppendLine("Start: GetActivityById for retrieving activity by id:" + id); tblActivity activity = dataContext.Activity.Find(id); Mapper.CreateMap <tblActivity, ActivityVM>(); ActivityVM objActivity = Mapper.Map <tblActivity, ActivityVM>(activity); tblFeaturedActivityQueue featuredActivityQueue = dataContext.FeaturedActivityQueue.Where(ce => ce.ActivityId == id).FirstOrDefault(); if (featuredActivityQueue != null) { objActivity.StartDate = featuredActivityQueue.StartDate; objActivity.EndDate = featuredActivityQueue.EndDate; } tblCredentials objCred = dataContext.Credentials.FirstOrDefault(c => c.Id == objActivity.TrainerId && c.UserType == Message.UserTypeTrainer); if (objCred != null) { objActivity.TrainerId = objCred.UserId; } return(objActivity); } catch { throw; } finally { traceLog.AppendLine("GetActivityById end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to delete activity /// </summary> /// <returns>void</returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/04/2015 /// </devdoc> public static void DeleteActivity(int id) { StringBuilder traceLog = null; using (LinksMediaContext dataContext = new LinksMediaContext()) { using (System.Data.Entity.DbContextTransaction dbTran = dataContext.Database.BeginTransaction()) { traceLog = new StringBuilder(); try { traceLog.AppendLine("Start: DeleteActivity --- " + DateTime.Now.ToLongDateString()); tblActivity activity = dataContext.Activity.Find(id); tblFeaturedActivityQueue featuredActivityQueue = dataContext.FeaturedActivityQueue.Where(ce => ce.ActivityId == id).FirstOrDefault(); /*Delete Related feateured activity for the activity*/ if (featuredActivityQueue != null) { dataContext.FeaturedActivityQueue.Remove(featuredActivityQueue); dataContext.SaveChanges(); } dataContext.Activity.Remove(activity); dataContext.SaveChanges(); dbTran.Commit(); } catch { dbTran.Rollback(); throw; } finally { traceLog.AppendLine("DeleteActivity end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } } }
/// <summary> /// Function to submit activity into database /// </summary> /// <returns>void</returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/01/2015 /// </devdoc> public static void SubmitActivity(ActivityVM objActivityVM) { StringBuilder traceLog = null; using (LinksMediaContext dataContext = new LinksMediaContext()) { using (System.Data.Entity.DbContextTransaction tran = dataContext.Database.BeginTransaction()) { traceLog = new StringBuilder(); try { traceLog.AppendLine("Start: SubmitActivity for creating activity"); tblCredentials objCred = dataContext.Credentials.FirstOrDefault(c => c.UserId == objActivityVM.TrainerId && c.UserType == Message.UserTypeTrainer); int trainerCredId = objCred.Id; objActivityVM.TrainerId = trainerCredId; Mapper.CreateMap <ActivityVM, tblActivity>(); tblActivity objActivity = Mapper.Map <ActivityVM, tblActivity>(objActivityVM); objActivity.CreatedDate = DateTime.Now; objActivity.ModifiedDate = objActivity.CreatedDate; // Add activity in to database dataContext.Activity.Add(objActivity); dataContext.SaveChanges(); tran.Commit(); } catch { tran.Rollback(); throw; } finally { traceLog.AppendLine("SubmitActivity end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } } }
/// <summary> /// Function to update activity /// </summary> /// <returns>void</returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/03/2015 /// </devdoc> public static void UpdateActivity(ActivityVM objActivityVM) { StringBuilder traceLog = null; using (LinksMediaContext dataContext = new LinksMediaContext()) { using (System.Data.Entity.DbContextTransaction tran = dataContext.Database.BeginTransaction()) { traceLog = new StringBuilder(); try { traceLog.AppendLine("Start: UpdateActivity for updating activity"); tblCredentials objCred = dataContext.Credentials.FirstOrDefault(c => c.UserId == objActivityVM.TrainerId && c.UserType == Message.UserTypeTrainer); int trainerCredId = objCred.Id; objActivityVM.TrainerId = trainerCredId; objActivityVM.ModifiedDate = DateTime.Now; tblActivity objActivity = dataContext.Activity.Where(ac => ac.ActivityId == objActivityVM.ActivityId).FirstOrDefault(); if (objActivity != null) { objActivity.AddressLine1 = objActivityVM.AddressLine1; objActivity.TrainerId = objActivityVM.TrainerId; objActivity.ModifiedDate = objActivityVM.ModifiedDate; objActivity.AddressLine2 = objActivityVM.AddressLine2; objActivity.DateOfEvent = objActivityVM.DateOfEvent; objActivity.Description = objActivityVM.Description; objActivity.NameOfActivity = objActivityVM.NameOfActivity; objActivity.Pic = objActivityVM.Pic; objActivity.PromotionText = objActivityVM.PromotionText; objActivity.State = objActivityVM.State; objActivity.Video = objActivityVM.Video; objActivity.Zip = objActivityVM.Zip; objActivity.LearnMore = objActivityVM.LearnMore; objActivity.City = Convert.ToInt32(objActivityVM.City); } dataContext.SaveChanges(); ///set activivty to featured queue in database if (objActivityVM.StartDate != null && objActivityVM.EndDate != null) { tblFeaturedActivityQueue featuredActivityQueue = dataContext.FeaturedActivityQueue.Where(ce => ce.ActivityId == objActivityVM.ActivityId).FirstOrDefault(); tblFeaturedActivityQueue featuredActivity = new tblFeaturedActivityQueue(); /*if featured activity is created then update else create new featured activity*/ if (featuredActivityQueue != null) { featuredActivityQueue.StartDate = objActivityVM.StartDate; featuredActivityQueue.ActivityId = objActivityVM.ActivityId; featuredActivityQueue.EndDate = objActivityVM.EndDate; } else { featuredActivity.StartDate = objActivityVM.StartDate; featuredActivity.ActivityId = objActivityVM.ActivityId; featuredActivity.EndDate = objActivityVM.EndDate; dataContext.FeaturedActivityQueue.Add(featuredActivity); } dataContext.SaveChanges(); } tran.Commit(); } catch { tran.Rollback(); throw; } finally { traceLog.AppendLine("UpdateActivity end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } } }