public ActionResult Create([Bind(Include = "Login, AllowedEdit")] Access access) { if (ModelState.IsValid) { db.Accesses.Add(access); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("CreateAccess")); }
public ActionResult Delete(int id, int pageDelete) { ExtremIncident incident = db.Incidents.Find(id); if (ModelState.IsValid) { db.Incidents.Remove(incident); db.SaveChanges(); } return(RedirectToAction("Index", new { page = pageDelete })); }
public static void GetHoliday(DateTime start, int countDays) { DutyContext db = new DutyContext(); WebClient webClient = new WebClient(); ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; DateTime finish = start.AddDays(countDays); while (start <= finish) { string url = "https://isdayoff.ru/" + start.ToString("yyyyMMdd") + "?cc=ru"; Console.WriteLine(start.ToString("yyyyMMdd")); string response = webClient.DownloadString(url); if (response == "1") { Console.WriteLine("Загружено"); db.Holidays.Add(new Holidays(start)); } start = start.AddDays(1); } db.SaveChanges(); Console.ReadKey(); }
public ActionResult Create([Bind(Include = "Name, Email, Login")] Employee employee) { using (DutyContext db = new DutyContext()) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("CreateEmployee")); } }
public ActionResult Delete(int id, int pageDelete) { using (DutyContext db = new DutyContext()) { Employee employee = db.Employees.Find(id); if (ModelState.IsValid) { db.Employees.Remove(employee); db.SaveChanges(); } return(RedirectToAction("Index", new { page = pageDelete })); } }
public ActionResult Edit(int[] selectedEmpId, DateTime dateEdit) { var duties = db.DutyLists.Where(x => x.DateDuty == dateEdit).ToList(); // все дежурства с такой датой foreach (DutyList s in duties) //очищаем все на эту дату { db.Entry(s).State = EntityState.Deleted; db.DutyLists.Remove(s); } for (int i = 0; i < selectedEmpId.Length; i++) // содаем новые { Employee newEmployee = db.Employees.Find(selectedEmpId[i]); DutyList newDutyList = new DutyList() { DateDuty = dateEdit, Employee = newEmployee }; db.Entry(newDutyList).State = EntityState.Added; db.DutyLists.Add(newDutyList); } db.SaveChanges(); return(RedirectToAction("Index", new { start = dateEdit })); }
public ActionResult CreateVacation(int selectedEmpId, DateTime Start, DateTime Finish) { Employee newEmployee = db.Employees.Find(selectedEmpId); var vacations = db.Vacations.Include(x => x.Employee).Where(x => x.Employee.EmployeeId == selectedEmpId && (x.Start >= Start && x.Start <= Finish || x.Start < Start && x.Finish >= Start)).ToList(); if (vacations.Any()) { foreach (Vacation vac in vacations) { db.Entry(vac).State = EntityState.Modified; vac.Start = Start; vac.Finish = Finish; } } else { Vacation newVacation = new Vacation(newEmployee, Start, Finish); db.Vacations.Add(newVacation); } db.SaveChanges(); return(RedirectToAction("Index", new { start = Start })); }