public HttpResponseMessage AddAdmin([FromBody] AddAdminDto adminDto)
 {
     return(Request.ExecuteProtectedAndWrapResult <AddAdminDto, AdminModel>(
                dto => AdminService.AddAdmin(dto),
                ModelState, adminDto
                ));
 }
 public IActionResult Create(Admin admin)
 {
     if (ModelState.IsValid)
     {
         _adminService.AddAdmin(admin);
     }
     return(RedirectToAction("Login"));
 }
Exemple #3
0
        public IActionResult Add(AdminInput param)
        {
            var response = new ReponseOutPut();

            response.Code    = "menu_add_success";
            response.Message = "新增账号成功";
            if (!ModelState.IsValid)
            {
                response.Status = ReutnStatus.Error;
                response.Code   = "param_vaild_error";

                var errorProperty = ModelState.Values.First(m => m.ValidationState == ModelValidationState.Invalid);
                response.Message = errorProperty.Errors.First().ErrorMessage;//验证不通过的 //全局配置一个验证不通过就不在验证了,只存在一个错误信息

                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            // 检查用户名是否重复
            var isExistUserName = _adminService.ExistAdminUserName(param.UserName);

            if (isExistUserName)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "username_is_exist";
                response.Message = "用户名已经存在";
                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            SysAdmin admin = _mapper.Map <AdminInput, SysAdmin>(param);

            admin.CreateBy         = _context.Admin.Id;
            admin.CreatebyName     = _context.Admin.UserName;
            admin.CreateDate       = DateTime.Now;
            admin.LastUpdateBy     = admin.CreateBy;
            admin.LastUpdateByName = admin.CreatebyName;
            admin.LastUpdateDate   = admin.CreateDate;



            var result = _adminService.AddAdmin(admin, param.RoleIds);

            if (result < 0)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "menu_add_error";
                response.Message = "新增账号失败";
            }

            return(new JsonResult(JsonConvert.SerializeObject(response)));
        }
Exemple #4
0
        public async Task <ActionResult> AddAdmin(Admin admin)
        {
            try
            {
                string token = Request.Headers["Authorization"].FirstOrDefault()?.Split(" ").Last();
                if (string.IsNullOrEmpty(token))
                {
                    return(new UnauthorizedResult());
                }
                if (!token.Equals(secretSetting.SecretKey))
                {
                    return(new UnauthorizedResult());
                }
                string res = await adminService.AddAdmin(admin);

                return(Ok(res));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
 public IActionResult AddAdmin([FromBody] AdminAddModel model)
 {
     adminService.AddAdmin(model);
     return(Ok());
 }
 public async Task <Admin> AddAdmin([FromBody] Admin admin)
 {
     return(await _adminService.AddAdmin(admin));
 }
Exemple #7
0
        public async Task <IActionResult> AddAdmin([FromBody] AdminModel admin)
        {
            var name = await _adminService.AddAdmin(AdminMapper.Map(admin));

            return(Ok(name));
        }
        public async Task <IActionResult> Add([FromBody] AdminModel admin)
        {
            var data = await _adminService.AddAdmin((AdminMapper.Map(admin)));

            return(Ok(data));
        }
Exemple #9
0
        private void SaveExecute(object parameter)
        {
            try
            {
                DateTime dateOfBirth;

                if (!ValidationClass.JMBGisValid(User.JMBG, out dateOfBirth))
                {
                    MessageBox.Show("JMBG is not valid");
                    return;
                }

                int age = ValidationClass.CountAge(dateOfBirth);
                if (age < 18)
                {
                    MessageBox.Show("JMBG is not valid\nAdmin has to be at least 18 years old");
                    return;
                }

                tblUser userInDb = userService.GetUserByUserName(User.Username);

                if (userInDb != null)
                {
                    string str1 = string.Format("User with this username exists\n" +
                                                "Enter another username");
                    MessageBox.Show(str1);
                    return;
                }

                userInDb = userService.GetUserByJMBG(User.JMBG);

                if (userInDb != null)
                {
                    string str1 = string.Format("User with this JMBG exists\n" +
                                                "Enter another JMBG");
                    MessageBox.Show(str1);
                    return;
                }
                var passwordBox = parameter as PasswordBox;
                var password    = passwordBox.Password;

                string encryptedString = EncryptionHelper.Encrypt(password);
                User.Gender        = Gender;
                User.MaritalStatus = MartialStatus;
                User.Password      = encryptedString;
                User = userService.AddUser(User);

                DateTime today = DateTime.Now;
                Admin.ExpiryDate        = today.AddDays(7);
                Admin.AdministratorType = SelctedType;
                Admin.UserID            = User.UserID;

                adminService.AddAdmin(Admin);
                string str = string.Format("You added new admin of type {0}", SelctedType);
                MessageBox.Show(str);
                view.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public async Task <IActionResult> AddAdmin([FromBody] AdminModelCreate adminModel)
        {
            var response = await _adminService.AddAdmin(adminModel);

            return(Ok(response));
        }
Exemple #11
0
        public async Task <IActionResult> Register([Bind("FirstName, LastName, Email, Password, Phone, Address, City, ZipCode")] RegisterViewModel model, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            if (await _userManager.FindByEmailAsync(model.Email) != null)
            {
                TempData["ErrorMessage"] = "Email déjà utilisé !";
                return(View());
            }

            var result = await _userManager.CreateAsync(new IdentityUser
            {
                Email    = model.Email,
                UserName = model.Email
            }, model.Password);

            if (result.Succeeded)
            {
                var location = locationService.AddLocation(new Location
                {
                    Address = model.Address,
                    City    = model.City,
                    ZipCode = model.ZipCode
                });

                var user = await _userManager.FindByEmailAsync(model.Email);

                string picturePath = "~/Content/AdminPictures/defaultAvatar.jpg";
                if (file != null)
                {
                    //Upload image
                    picturePath = FileUploader.UploadImage(file, "AdminPictures");
                }

                var admin = new Admin
                {
                    FirstName         = model.FirstName,
                    LastName          = model.LastName,
                    Email             = model.Email,
                    Phone             = model.Phone,
                    Location          = location,
                    HasValidatedEmail = false,
                    IdentityId        = user.Id,
                    PicturePath       = picturePath
                };

                adminService.AddAdmin(admin);

                TempData["Message"] = "Inscription effectuée. Vous allez recevoir un email pour valider votre compte.";
                //Send Verification Email
                var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                SendVerificationEmail(admin, user.Id, token, false);

                return(RedirectToAction("Login"));
            }
            else
            {
                TempData["ErrorMessage"] = result.Errors.ToString();
                return(View());
            }
        }