public User Map(CreateOrEditViewModel createOrEdit)
        {
            User user = new User();

            if (createOrEdit.Id != null)
            {
                user = this.RequestHandler.Storage.GetRepository <IUserRepository>().WithKey((int)createOrEdit.Id);
            }

            else
            {
                user.Created = DateTime.Now;
            }

            user.Name = createOrEdit.Name;
            return(user);
        }
Ejemplo n.º 2
0
        public IActionResult CreateOrEdit(CreateOrEditViewModel createOrEdit)
        {
            if (this.ModelState.IsValid)
              {
            User user = new CreateOrEditViewModelMapper(this).Map(createOrEdit);

            if (createOrEdit.Id == null)
              this.Storage.GetRepository<IUserRepository>().Create(user);

            else this.Storage.GetRepository<IUserRepository>().Edit(user);

            this.Storage.Save();
            this.CreateOrEditUserRoles(user);
            return this.Redirect(this.Request.CombineUrl("/backend/users"));
              }

              return this.CreateRedirectToSelfResult();
        }