public async Task <IActionResult> Edit(int id, [Bind("EconomicPermissionId,PermissionId,StartDate,FinalDate,NumberOfDays")] EconomicPermissions economicPermissions) { if (id != economicPermissions.EconomicPermissionId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(economicPermissions); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EconomicPermissionsExists(economicPermissions.EconomicPermissionId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PermissionId"] = new SelectList(_context.Permission, "PermissionId", "PermissionId", economicPermissions.PermissionId); return(View(economicPermissions)); }
//public async Task<IActionResult> Create([Bind("PermissionId,PermissionType,EmployeeId,Autorize,requestDate,EconomicPermissionId,PermissionId,StartDate,FinalDate,NumberOfDays")] EconomicPermissions economicPermissions, Permission permission) //{ // if (ModelState.IsValid) // { // int numberOfDays; // permission.RequestDate = DateTime.Now; // numberOfDays = (int)(economicPermissions.FinalDate - economicPermissions.StartDate).Value.TotalDays + 1; // economicPermissions.NumberOfDays = numberOfDays; // permission.Autorize = 0; // _context.Add(permission); // await _context.SaveChangesAsync(); // economicPermissions.PermissionId = permission.PermissionId; // _context.Add(economicPermissions); // await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); // } // ViewData["PermissionId"] = new SelectList(_context.Permission, "PermissionId", "PermissionId", economicPermissions.PermissionId); // return View(economicPermissions); //} public async Task <IActionResult> Createto(int?id, [Bind("PermissionId,PermissionType,EmployeeId,Autorize,requestDate,EconomicPermissionId,PermissionId,StartDate,FinalDate,NumberOfDays")] EconomicPermissions economicPermissions, Permission permission) { if (ModelState.IsValid) { int numberOfDays; permission.RequestDate = DateTime.Now; numberOfDays = (int)(economicPermissions.FinalDate - economicPermissions.StartDate).Value.TotalDays + 1; economicPermissions.NumberOfDays = numberOfDays; permission.Autorize = "En Espera"; _context.Add(permission); await _context.SaveChangesAsync(); economicPermissions.PermissionId = permission.PermissionId; _context.Add(economicPermissions); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("", "Permissions", new { id = permission.EmployeeId })); } permissionTypes = _context.PermissionTypes.Where(c => c.PermissionTypeId == 1).ToList(); Employees = _context.Employee.Where(c => c.EmployeeId == id).ToList(); //Permissions = _context.Permission.Where(c => c.EmployeeId == id).ToList(); ViewBag.Employee = Employees.First(); ViewBag.RequestDate = DateTime.Now; // Query Utilizado para saber si el Empleado ya utilizó su día de cumpleaños int count = _context.BirthdayPermissions.Count(t => t.Permission.EmployeeId == id && t.Permission.PermissionType == 2); ViewBag.BirthdayPermissionsCount = count; eco = _context.EconomicPermissions.Where(s => s.Permission.EmployeeId == id).ToList(); ViewBag.EconomicPermissions = eco; ViewData["EmployeeId"] = new SelectList(Employees, "EmployeeId", "EmployeeId"); ViewData["PermissionType"] = new SelectList(permissionTypes, "PermissionTypeId", "PermissionTypeDesc"); return(View()); }
public async Task <IActionResult> Create([Bind("PermissionId,PermissionType,EmployeeId,Autorize,requestDate")] Permission permission, BirthdayPermissions birthdayPermissions, HoursPermissions hoursPermissions, EconomicPermissions economicPermissions) { if (ModelState.IsValid) { // permission.EmployeeId = Int32.Parse((Request.Form["employeeid"].ToString())); permission.RequestDate = DateTime.Now; permission.Autorize = "En Espera"; int permissiontype = Int32.Parse((Request.Form["permissiontype"].ToString())); int numberOfDays; _context.Add(permission); await _context.SaveChangesAsync(); switch (permissiontype) { case 1: economicPermissions.PermissionId = permission.PermissionId; economicPermissions.StartDate = Convert.ToDateTime(Request.Form["startdate"].ToString()); economicPermissions.FinalDate = Convert.ToDateTime(Request.Form["finaldate"].ToString()); numberOfDays = (int)(economicPermissions.FinalDate - economicPermissions.StartDate).Value.TotalDays + 1; economicPermissions.NumberOfDays = numberOfDays; _context.Add(economicPermissions); await _context.SaveChangesAsync(); break; case 2: birthdayPermissions.PermissionId = permission.PermissionId; birthdayPermissions.GrantedDayDate = Convert.ToDateTime(Request.Form["birthdayDayPicker"].ToString()); _context.Add(birthdayPermissions); await _context.SaveChangesAsync(); break; case 3: hoursPermissions.PermissionId = permission.PermissionId; hoursPermissions.HoursRange = Request.Form["hoursRange"].ToString(); hoursPermissions.Reason = Request.Form["hours_reason"].ToString(); _context.Add(hoursPermissions); await _context.SaveChangesAsync(); break; default: break; } if (permission.PermissionType == 1) { return(RedirectToAction("Index", "", new { id = permission.PermissionId })); } else if (permission.PermissionType == 2) { return(RedirectToAction("Index", "BirthdayPermissions")); } } /* ViewData["EmployeeId"] = new SelectList(_context.Employee, "EmployeeId", "EmployeeId", permission.EmployeeId); * ViewData["PermissionType"] = new SelectList(_context.PermissionTypes, "PermissionTypeId", "PermissionTypeId", permission.PermissionType);*/ return(View(permission)); }