public async Task <IActionResult> Create([Bind("ID,Nombre,Descripcion,icon")] ServicesData servicesData)
        {
            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 notification = new Notifications();
                TempData["sms"]      = "Un nuevo servicio se ha publicado correctamente";
                ViewBag.sms          = TempData["sms"];
                notification.Detalle = ViewBag.sms;
                notification.Section = "Servicios";
                notification.Tipo    = "check";
                notification.Time    = DateTime.Now;
                notification         = _empleadosData.AddNotification(notification);
                _context.Add(servicesData);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(servicesData));
        }
        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));
            }
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("ID,Nombre,Description,Image")] GaleryViewModel model, IFormFile img)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction(nameof(AccountController.Login), "Account"));
            }

            if (ModelState.IsValid)
            {
                var newPicture = new GaleryData();
                var image      = img;

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

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await image.CopyToAsync(stream);
                    }
                    newPicture.Image = image.FileName;
                }
                else
                {
                    var path = "default.png";
                    newPicture.Image = path;
                }

                newPicture.Nombre      = model.Nombre;
                newPicture.Description = model.Description;
                newPicture             = _empleadosData.AddPicture(newPicture);
                var notification = new Notifications();

                TempData["sms"]      = "Campo añadido correctamente";
                ViewBag.sms          = TempData["sms"];
                notification.Detalle = ViewBag.sms;
                notification.Section = "Galeria";
                notification.Tipo    = "check";
                notification.Time    = DateTime.Now;
                notification         = _empleadosData.AddNotification(notification);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("ID,Option,Image")] ChooseUs chooseUs, IFormFile Img)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction(nameof(AccountController.Login), "Account"));
            }

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

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await Img.CopyToAsync(stream);
                    }
                    chooseUs.Image = Img.FileName;
                }
                else
                {
                    var path = "default.png";
                    chooseUs.Image = path;
                }
                var notification = new Notifications();

                TempData["sms"]      = "Campo añadido correctamente";
                ViewBag.sms          = TempData["sms"];
                notification.Detalle = ViewBag.sms;
                notification.Section = "Razones para elegirnos";
                notification.Tipo    = "check";
                notification.Time    = DateTime.Now;
                notification         = _empleadosData.AddNotification(notification);

                chooseUs = _empleadosData.AddReason(chooseUs);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(chooseUs));
        }
Exemple #5
0
        public async Task <IActionResult> Index(IndexViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var email = user.Email;

            if (model.Email != email)
            {
                var setEmailResult = await _userManager.SetEmailAsync(user, model.Email);

                if (!setEmailResult.Succeeded)
                {
                    throw new ApplicationException($"Unexpected error occurred setting email for user with ID '{user.Id}'.");
                }
            }

            var phoneNumber = user.PhoneNumber;

            if (model.PhoneNumber != phoneNumber)
            {
                var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, model.PhoneNumber);

                if (!setPhoneResult.Succeeded)
                {
                    throw new ApplicationException($"Unexpected error occurred setting phone number for user with ID '{user.Id}'.");
                }
            }

            var usuario  = model.Usuario;
            var empleado = model.Empleado;

            usuario.Id = user.Id;


            if (usuario.Id == empleado.IdUsuario)
            {
                model.Address         = model.Empleado.Address;
                model.Apellido        = model.Empleado.Apellido;
                model.Celular         = model.Empleado.Celular;
                model.Nombre          = empleado.Nombre;
                model.FechaNacimiento = empleado.FechaNacimiento;
                model.Image           = empleado.Image;
            }



            //........................................................................................



            StatusMessage = "Tu perfil ha sido perfectamente actualizado";
            var notification = new Notifications();

            notification.Detalle = StatusMessage;
            notification.Tipo    = "check";
            notification.Section = "Mi Perfil";
            notification         = _EmpleadosData.AddNotification(notification);
            return(RedirectToAction(nameof(Index)));
        }