Example #1
0
 public static void TransferModel(this AddEditUserViewModel model, ref Entidad user)
 {
     user.Nombre   = model.Name;
     user.Apellido = model.LastName;
     user.Password = model.Password;
     user.ID_email = model.Email;
 }
Example #2
0
        public ActionResult AddEditUser(AddEditUserViewModel model)
        {
            var user = _cdb.CtsUser.Include(s => s.CtsRoles)
                       .Where(x => x.Login == model.UserLogin)
                       .FirstOrDefault(s => s.Domain == model.UserDomain);

            if (user == null)
            {
                user = new CtsUser()
                {
                    Login  = model.UserLogin,
                    Domain = model.UserDomain
                };
                _cdb.CtsUser.Add(user);
            }
            foreach (var userRole in user.CtsRoles)
            {
                if (!model.CtsRoles.ContainsKey(userRole.RoleName))
                {
                    model.CtsRoles.Add(userRole.RoleName, true);
                }
            }

            user.CtsRoles.Clear();
            user.CtsRoles = model.CtsRoles?
                            .Where(x => x.Value)
                            .Select(x => _cdb.CtsRole.Find(x.Key))
                            .ToList();
            _cdb.SaveChanges();

            return(RedirectToAction(model.ReturnView ?? "index"));
        }
Example #3
0
        public ActionResult AddEditUser(AddEditUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                TryUpdateModel(model);
                Debug.WriteLine("AEuser - no es valido");
                return(View(model));
            }
            try
            {
                /*TODO O NADA*/
                using (var transactionScope = new TransactionScope())
                {
                    EntidadDAO.AddEditEntity(model);
                    Debug.WriteLine("AEuser - antes de transacionComplete");
                    transactionScope.Complete();
                    Debug.WriteLine("AEuser - redireccionando al Index");

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                model.CargarDatos(EntidadDAO.context, model.Email);
                Debug.WriteLine("AEuser - catch");
                TryUpdateModel(model);
                return(View(model));
            }
        }
Example #4
0
        public ActionResult AddEditUser(String Email)
        {
            var viewModel = new AddEditUserViewModel();

            viewModel.CargarDatos(EntidadDAO.context, Email);
            return(View(viewModel));
        }
        public virtual Task <HttpStatusCode> SendEmailNewUser(AddEditUserViewModel model)
        {
            var messageSubject = $"[Add New User] - {model.Name}";

            _logger.LogInformation("Sending Add New User email");

            var attachments = new List <IFormFile>();

            var emailBody = new AddUser()
            {
                GroupName = model.Name, Role = GetRoleByInitial(model.GroupAdministratorItem.Permission)
            };

            return(_emailClient.SendEmailToService(new EmailMessage(messageSubject, _emailClient.GenerateEmailBodyFromHtml(emailBody),
                                                                    _fromEmail,
                                                                    model.GroupAdministratorItem.Email,
                                                                    attachments)));
        }
Example #6
0
        public ActionResult AddEditUser(string userLogin, string userDomain, string[] roles)
        {
            AddEditUserViewModel model;
            var ctsRoles = roles?.Select(r => _cdb.CtsRole.Find(r)) ?? _cdb.CtsRole;
            var user     = _cdb.CtsUser.Find(userLogin, userDomain);

            if (user == null)
            {
                model = new AddEditUserViewModel(userLogin, userDomain, ctsRoles.ToList());
            }
            else
            {
                _cdb.Entry(user).Collection(x => x.CtsRoles).Load();
                model = new AddEditUserViewModel(user, ctsRoles.ToList());
            }

            model.AllRoles   = roles == null;
            model.ReturnView = HttpContext.Request.UrlReferrer?.Segments.Last();
            return(View(model));
        }
Example #7
0
        public void AddEditEntity(AddEditUserViewModel model)
        {
            var user = new Entidad();

            if (model.Exist(context))//editar
            {
                Debug.WriteLine("AEuser - if: editar");
                user = context.Entidad.Find(model.Email);
            }
            else
            {//agregar
                Debug.WriteLine("AEuser - else: agregar");
                context.Entidad.Add(user);
            }

            model.TransferModel(ref user);

            Debug.WriteLine("AEuser - antes de guardar");
            context.SaveChanges();
        }
        public async Task <ActionResult> Create(AddEditUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var aspnetuser = new AspNetUser()
                {
                    UserName             = model.UserName,
                    FirstName            = model.FirstName,
                    MiddleInitial        = model.MiddleInitial,
                    LastName             = model.LastName,
                    Address1             = model.Address1,
                    Address2             = model.Address2,
                    City                 = model.City,
                    Province             = model.Province,
                    District             = model.District,
                    PostalCode           = model.PostalCode,
                    IsUserActive         = model.IsUserActive,
                    Email                = model.Email,
                    EmailConfirmed       = true, //set
                    PasswordHash         = new PasswordHasher().HashPassword(model.Password),
                    PhoneNumber          = model.PhoneNumber,
                    PhoneNumberConfirmed = false, //set
                    AlternatePhoneNumber = model.AlternatePhoneNumber.ToString(),
                    TwoFactorEnabled     = true,  //set
                    LockoutEnabled       = false,
                    AccessFailedCount    = 0,
                    CreatedDate          = DateTime.Now,
                    LastUpdatedDate      = DateTime.Now,
                    LastUpdatedByUser    = await _identityManager.GetLoggedInUserIdAsync()
                };
                bool isUserCreated = await _identityManager.CreateUserAsync(aspnetuser);

                return(RedirectToAction(nameof(SearchUsers)));
            }

            return(View(model));
        }