예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("BirthdayPermissionId,PermissionId,GrantedDayDate")] BirthdayPermissions birthdayPermissions)
        {
            if (id != birthdayPermissions.BirthdayPermissionId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(birthdayPermissions);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BirthdayPermissionsExists(birthdayPermissions.BirthdayPermissionId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PermissionId"] = new SelectList(_context.Permission, "PermissionId", "PermissionId", birthdayPermissions.PermissionId);
            return(View(birthdayPermissions));
        }
예제 #2
0
        public async Task <IActionResult> Createto([Bind("PermissionId,PermissionType,EmployeeId,Autorize,requestDate,BirthdayPermissionId,PermissionId,GrantedDayDate")] BirthdayPermissions birthdayPermissions, Permission permission)
        {
            if (ModelState.IsValid)
            {
                permission.RequestDate = DateTime.Now;
                permission.Autorize    = "En Espera";
                _context.Add(permission);
                await _context.SaveChangesAsync();

                birthdayPermissions.PermissionId = permission.PermissionId;
                _context.Add(birthdayPermissions);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("", "Permissions", new { id = permission.EmployeeId }));
            }
            ViewData["PermissionId"] = new SelectList(_context.Permission, "PermissionId", "PermissionId", birthdayPermissions.PermissionId);
            return(View(birthdayPermissions));
        }
        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));
        }