public IActionResult Add(DateTime date, string description, string color) { var record = new PlanRecord { Date = date, Description = description, Color = (color == "#000000") ? "#ffffff" : color // turn black into white }; _dbcontext.PlanRecords.Add(record); _dbcontext.SaveChanges(); return(RedirectToAction("Plan", "Home")); }
public async Task <ActionResult> CreateNewPlan(CreateNewPlanViewModel model) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); var context = HttpContext.GetOwinContext().Get <ApplicationDbContext>(); if (ModelState.IsValid) { if (model.Id == 0) { PlanRecord planRecord = new PlanRecord() { From = GetCity(model.From), To = GetCity(model.To), Month = model.Period, Number = model.Plan }; context.PlanRecords.Add(planRecord); context.SaveChanges(); return(RedirectToAction("Index", new { Message = ManageMessageId.AddNewPeriod })); } var planRecordForUpdate = (from c in context.PlanRecords .Include("From") .Include("To") where c.Id == model.Id select c).FirstOrDefault(); planRecordForUpdate.From = GetCity(model.From); planRecordForUpdate.To = GetCity(model.To); planRecordForUpdate.Month = model.Period; planRecordForUpdate.Number = model.Plan; context.SaveChanges(); return(RedirectToAction("Index", new { Message = ManageMessageId.UpdatePlanRecord })); } // Это сообщение означает наличие ошибки; повторное отображение формы return(View(model)); }
protected override void Seed(TestProj.Models.ApplicationDbContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context)); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var role_admin = new IdentityRole { Name = "admin" }; var role_user1 = new IdentityRole { Name = "user1" }; var role_user2 = new IdentityRole { Name = "user2" }; roleManager.Create(role_admin); roleManager.Create(role_user1); roleManager.Create(role_user2); // create Admin var admin = new ApplicationUser { Email = "*****@*****.**", UserName = "******" }; string password = "******"; var result = userManager.Create(admin, password); if (result.Succeeded) { // добавляем для пользователя роль userManager.AddToRole(admin.Id, role_admin.Name); } //Create User1 ApplicationUser user1 = new ApplicationUser { Email = "*****@*****.**", UserName = "******", Report1 = true }; result = userManager.Create(user1, password); if (result.Succeeded) { userManager.AddToRole(user1.Id, role_user1.Name); } //Create User2 ApplicationUser user2 = new ApplicationUser { Email = "*****@*****.**", UserName = "******", Report2 = true }; result = userManager.Create(user2, password); if (result.Succeeded) { userManager.AddToRole(user2.Id, role_user2.Name); } // user2.Report2 = true; user1.Report1 = true; userManager.Update(admin); userManager.Update(user1); userManager.Update(user2); //Create some cities City dnepr = new City() { Name = "Dnepr" }; City cherson = new City() { Name = "Cherson" }; City cherkasi = new City() { Name = "Cherkasi" }; City charkov = new City() { Name = "Charkov" }; context.Cities.AddOrUpdate(dnepr); context.Cities.AddOrUpdate(cherson); context.Cities.AddOrUpdate(cherkasi); context.Cities.AddOrUpdate(charkov); //Create records for reports PlanRecord record = new PlanRecord() { From = dnepr, To = cherson, Month = new DateTime(2014, 1, 1), Number = 30 }; record.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 1), Number = 4 }); record.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 2), Number = 2 }); record.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 3), Number = 3 }); record.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 4), Number = 1 }); record.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 5), Number = 5 }); PlanRecord record1 = new PlanRecord() { From = dnepr, To = cherkasi, Month = new DateTime(2014, 2, 1), Number = 55 }; record1.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 2, 1), Number = 4 }); record1.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 2, 2), Number = 2 }); record1.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 2, 3), Number = 3 }); record1.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 2, 4), Number = 1 }); record1.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 2, 5), Number = 5 }); PlanRecord record2 = new PlanRecord() { From = dnepr, To = charkov, Month = new DateTime(2014, 1, 1), Number = 62 }; record2.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 1), Number = 5 }); record2.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 2), Number = 5 }); record2.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 3), Number = 5 }); record2.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 4), Number = 5 }); record2.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 5), Number = 5 }); PlanRecord record3 = new PlanRecord() { From = charkov, To = dnepr, Month = new DateTime(2014, 1, 1), Number = 13, }; record3.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 1), Number = 6 }); record3.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 2), Number = 6 }); record3.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 3), Number = 6 }); PlanRecord record4 = new PlanRecord() { From = charkov, To = cherkasi, Month = new DateTime(2014, 1, 1), Number = 12 }; record4.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 1), Number = 2 }); record4.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 1, 2), Number = 2 }); PlanRecord record5 = new PlanRecord() { From = cherkasi, To = charkov, Month = new DateTime(2014, 2, 1), Number = 13 }; record5.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 2, 1), Number = 3 }); record5.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 2, 2), Number = 3 }); record5.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 2, 1), Number = 3 }); record5.DayFactRecords.Add(new FactRecord() { Date = new DateTime(2014, 2, 2), Number = 3 }); context.PlanRecords.AddOrUpdate(record); context.PlanRecords.AddOrUpdate(record1); context.PlanRecords.AddOrUpdate(record2); context.PlanRecords.AddOrUpdate(record3); context.PlanRecords.AddOrUpdate(record4); context.PlanRecords.AddOrUpdate(record5); base.Seed(context); }
public string Editc() { string id = Request["Id"]; string classNo = Request["ClassNo"]; string headmasterName = Request["HeadmasterName"]; string headmasterId = Request["HeadmasterId"]; string classDate = Request["ClassDate"]; string useTime = Request["UseTime"]; string courseName = Request["CourseName"]; string courseId = Request["CourseId"]; string classTime = Request["ClassTime"]; string classRoomNo = Request["ClassRoomNo"]; string classRoomId = Request["ClassRoomId"]; string teacherNames = Request["TeacherNames"]; string teacherIds = Request["TeacherIds"]; string parentName = Request["ParentName"]; var changeconent = new StringBuilder(); var model = unitOfWork.SchedulingDetailBLL.GetEntityByID(new Guid(id)); if (model.ClassDate != Convert.ToDateTime(classDate)) { changeconent.Append("排课日期变更;"); } if (model.ClassNo != classNo) { changeconent.Append("班级变更;"); } if (model.CourseName != courseName) { changeconent.Append("课程变更;"); } if (model.ClassRoomNo != classRoomNo) { changeconent.Append("教室变更;"); } if (model.ClassTime != classTime) { changeconent.Append("上课时间变更;"); } if (model.TeacherNames != teacherNames) { changeconent.Append("培训师变更;"); } model.ClassNo = classNo; model.HeadmasterId = new Guid(headmasterId); model.HeadmasterName = headmasterName; model.ClassDate = Convert.ToDateTime(classDate); model.WeekInfo = GetDayOfWeek(Convert.ToDateTime(model.ClassDate)); model.CourseName = courseName; model.CourseId = new Guid(courseId); model.ClassTime = classTime; model.ClassRoomNo = classRoomNo; model.ClassRoomId = new Guid(classRoomId); model.TeacherNames = teacherNames; model.TeacherIds = teacherIds; model.ParentName = parentName; model.UseTime = useTime; model.LastModifyId = CurrentUser.UserId; model.LastModifyName = CurrentUser.UserName; model.LastModifyTime = System.DateTime.Now; try { // var cd = Convert.ToDateTime(classDate); Expression<Func<SchedulingDetail, bool>> where = PredicateExtensionses.True<SchedulingDetail>(); where = where.And(m => m.ClassTime == classTime && m.ClassDate == model.ClassDate && m.ClassRoomNo == classRoomNo&&m.Id!=model.Id); var models = unitOfWork.SchedulingDetailBLL.GetEntitys(where); if (models.Any()) //时间一样,教室一样 { return "同时间的教室已被占用,占用班级:" + models.ToArray()[0].ClassNo; } Expression<Func<SchedulingDetail, bool>> where1 = PredicateExtensionses.True<SchedulingDetail>(); where1 = where1.And(m => m.ClassTime == classTime && m.ClassDate == model.ClassDate && m.TeacherNames == teacherNames && m.Id != model.Id); var models1 = unitOfWork.SchedulingDetailBLL.GetEntitys(where1); if (models1.Any()) //时间一样,培训师一样 { return "同时间的老师已有课程安排,已安排班级:" + models1.ToArray()[0].ClassNo; } Expression<Func<SchedulingDetail, bool>> where2 = PredicateExtensionses.True<SchedulingDetail>(); where2 = where2.And(m => m.ClassTime == classTime && m.ClassDate == model.ClassDate && m.ClassNo == classNo && m.Id != model.Id); var models2 = unitOfWork.SchedulingDetailBLL.GetEntitys(where2); if (models2.Any()) //时间一样,班级一样 { return "同时间的班级已有课程安排,已安排课程:" + models1.ToArray()[0].CourseName; } var model1 = unitOfWork.SchedulingPlanBLL.GetEntityByID(model.ParentId); var mod = new PlanRecord(); mod.ChangeTime = System.DateTime.Now; mod.ChangeContent = changeconent.ToString(); mod.ChangerId = CurrentUser.UserId; mod.ChangerName = CurrentUser.UserName; mod.Id = Guid.NewGuid(); mod.Name = model1.Name; mod.PeriodsNo = model1.PeriodsNo; mod.PlanId = model1.Id; mod.PeriodsNo = model1.PeriodsNo; mod.PlanYear = model1.PlanYear; unitOfWork.PlanRecordBLL.InsertEntity(mod); unitOfWork.SchedulingDetailBLL.UpdateEntity(model); unitOfWork.Save(); return ""; } catch (Exception ex) { Log.Error("修改排班计划信息异常:" + ex.Message, ex); return "系统异常,请联系管理员!"; } }