Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ID,Nombre,Apellido,Sexo,Address,Cargo,Celular,Sueldo,FechaNacimiento,FechaIngreso,Image")] PeopleData model, IFormFile img)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction(nameof(AccountController.Login), "Account"));
                // throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }
            if (ModelState.IsValid)
            {
                var newEmpleado = new PeopleData();

                var profileImage = img;

                if (profileImage != null)
                {
                    var path = Path.Combine(
                        Directory.GetCurrentDirectory(), "wwwroot/images",
                        profileImage.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await profileImage.CopyToAsync(stream);
                    }
                    newEmpleado.Image = profileImage.FileName;
                }
                else
                {
                    var path = "user.png";
                    newEmpleado.Image = path;
                }
                newEmpleado.Address         = model.Address;
                newEmpleado.Apellido        = model.Apellido;
                newEmpleado.Cargo           = model.Cargo;
                newEmpleado.Celular         = model.Celular;
                newEmpleado.FechaIngreso    = model.FechaIngreso;
                newEmpleado.FechaNacimiento = model.FechaNacimiento;
                newEmpleado.Nombre          = model.Nombre;
                newEmpleado.Sexo            = model.Sexo;
                newEmpleado.Sueldo          = model.Sueldo;
                var notification = new Notifications();

                TempData["sms"]      = "Se agregó al empleado " + model.Nombre + " exitosamente a la lista de empleados.";
                ViewBag.sms          = TempData["sms"];
                notification.Detalle = ViewBag.sms;
                notification.Section = "Empleados";
                notification.Tipo    = "check";
                notification.Time    = DateTime.Now;
                notification         = _empleadosData.AddNotification(notification);
                newEmpleado          = _empleadosData.Add(newEmpleado);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,Nombre,Apellido,Sexo,Address,Cargo,Celular,Sueldo,FechaNacimiento,FechaIngreso,Image")] PeopleDataViewModel model, IFormFile img)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction(nameof(AccountController.Login), "Account"));
                // throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }
            if (ModelState.IsValid)
            {
                var newEmpleado = new PeopleData();

                var profileImage = model.Image;

                if (profileImage != null)
                {
                    var path = Path.Combine(
                        Directory.GetCurrentDirectory(), "wwwroot/images",
                        profileImage.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await profileImage.CopyToAsync(stream);
                    }
                    newEmpleado.Image = profileImage.FileName;
                }
                else
                {
                    var path = "user.png";
                    newEmpleado.Image = path;
                }
                newEmpleado.Address         = model.Address;
                newEmpleado.Apellido        = model.Apellido;
                newEmpleado.Cargo           = model.Cargo;
                newEmpleado.Celular         = model.Celular;
                newEmpleado.FechaIngreso    = model.FechaIngreso;
                newEmpleado.FechaNacimiento = model.FechaNacimiento;
                newEmpleado.Nombre          = model.Nombre;
                newEmpleado.Sexo            = model.Sexo;
                newEmpleado.Sueldo          = model.Sueldo;

                newEmpleado = _empleadosData.Add(newEmpleado);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(model));
            }
        }