Пример #1
0
        public ActionResult CrearUsuario(UsuarioViewModel model)
        {
            //if (!ModelState.IsValid)
            //    return View();
            try
            {
                var id = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;

                model.Id_Usuario = Int32.Parse(id);


                if (userService.ExisteUsuarioPorCodigo(model.codigo))
                {
                    return(Json(new { success = false, err = _sharedLocalizer["usuarioCodigoExiste"].ToString() }));
                }

                if (userService.ExisteUsuarioPorCorreo(model.correo))
                {
                    return(Json(new { success = false, err = _sharedLocalizer["usuarioCorreoExiste"].ToString() }));
                }

                var user = userMap.Create(model);

                if (user != null)
                {
                    //var uId = userService.GetUsuarioConPerfiles(user.codigo);
                    var idEmpresa         = (int)HttpContext.Session.GetInt32("idEmpresa");
                    var empresaUsuarioRel = new TbSeEmpresaUsuario
                    {
                        IdEmpresa = idEmpresa,
                        Estado    = true,
                        IdUsuario = user.id
                    };
                    var configUsuario = new TbSeUsuarioConfiguraion
                    {
                        Idioma    = "es",
                        IdUsuario = user.id,
                        Tema      = "TemaCombinado"
                    };

                    var resCU = userService.CreateOrUpdateConfiguracion(configUsuario);
                    var resEU = userService.CreateEmpresaUsuarioRel(empresaUsuarioRel);

                    return(Json(new { success = true, cod = user.codigo }));
                }
                else
                {
                    return(Json(new { success = false, err = _sharedLocalizer["errorGeneral"].ToString() }));
                }
            }
            catch (Exception ex)
            {
                AltivaLog.Log.Insertar(ex.ToString(), "Error");
                return(BadRequest());

                throw;
            }
        }
        public TbSeEmpresaUsuario CreateEmpresaUsuarioRel(TbSeEmpresaUsuario domain)
        {
            try
            {
                context.TbSeEmpresaUsuario.Add(domain);
                context.SaveChanges();
                return(domain);
            }
            catch (Exception)
            {
                return(null);

                throw;
            }
        }
Пример #3
0
        public TbSeEmpresaUsuario CreateEmpresaUsuarioRel(TbSeEmpresaUsuario domain)
        {
            try
            {
                context.TbSeEmpresaUsuario.Add(domain);
                context.SaveChanges();
                return(domain);
            }
            catch (Exception ex)
            {
                AltivaLog.Log.Insertar(ex.ToString(), "Error");
                return(null);

                throw;
            }
        }
Пример #4
0
 public TbSeEmpresaUsuario CreateEmpresaUsuarioRel(TbSeEmpresaUsuario domain)
 {
     return(repository.CreateEmpresaUsuarioRel(domain));
 }
        public ActionResult CrearUsuario(UsuarioViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            try
            {
                var id = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;

                model.Id_Usuario = Int32.Parse(id);


                if (userService.ExisteUsuarioPorCodigo(model.codigo))
                {
                    ModelState.AddModelError(string.Empty, "El código ya existe en el sistema");
                    return(View(model));
                }

                if (userService.ExisteUsuarioPorCorreo(model.correo))
                {
                    ModelState.AddModelError(string.Empty, "El correo ya existe en el sistema");
                    return(View(model));
                }

                var user = userMap.Create(model);

                if (user != null)
                {
                    var uId               = userService.GetUsuarioConPerfiles(user.codigo);
                    var idEmpresa         = (int)HttpContext.Session.GetInt32("idEmpresa");
                    var empresaUsuarioRel = new TbSeEmpresaUsuario
                    {
                        IdEmpresa = idEmpresa,
                        Estado    = true,
                        IdUsuario = uId.Id
                    };
                    var configUsuario = new TbSeUsuarioConfiguraion
                    {
                        Idioma    = "es",
                        IdUsuario = uId.Id,
                        Tema      = "TemaCombinado"
                    };

                    var resCU = userService.CreateOrUpdateConfiguracion(configUsuario);
                    var resEU = userService.CreateEmpresaUsuarioRel(empresaUsuarioRel);

                    if (resEU != null && resCU != null)
                    {
                        return(RedirectToAction("CuentaUsuario", new { codigo = model.codigo }));
                    }
                    else
                    {
                        userService.Delete(uId);
                        return(View(string.Empty, "Error al crear la relación del usuario y la empresa"));
                    }
                }
                else
                {
                    return(View(string.Empty, "Error al crear el usuario"));
                }
            }
            catch
            {
                return(View(string.Empty, "Error al crear el usuario"));

                throw;
            }
        }