public async Task <ActionResult> New(Account account) { if (ModelState.IsValid) { try { await _service.Add(account); return(RedirectToAction(nameof(Index))); } catch (ModelValidationException e) { ModelState.AddModelError("AccountValidation", e.Message); return(View(account)); } catch (DbUpdateException e) { TempData["ErrorMessage"] = e.Message; return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message)); } } else { return(View(account)); } }
public async Task <IActionResult> Create([Bind("Username,Password,Email")] Account account, string confirmPassword) { if (account.Password != confirmPassword) { ViewData["ConfirmPasswordError"] = "The passwords do not match."; return(View(account)); } if (ModelState.IsValid) { account.AccountId = GenerateAccountId(account.Username); account.Password = new PasswordHasher <Account>().HashPassword(account, account.Password); account.Created = DateTime.Now; if (_accountService.Any(account.AccountId)) { ViewData["UsernameError"] = "An account with that username already exists."; } else if (await _accountService.Add(account).Success()) { await _authService.SignIn(HttpContext, account); SetSessionString(HomeController.WelcomeMessageKey, $"Welcome {account.Username}!"); return(RedirectToAction(nameof(HomeController.Index), "Recipes")); } } return(View(account)); }
public void Service__GetsAllAccounts() { // Arrange var accountList = new[] { GetMockAccount(0987890UL, "test1", 123m, 456m, false), GetMockAccount(1987098UL, "test2", 789m, 010m, true) }; var options = new DbContextOptionsBuilder <AccountingContext>() .UseInMemoryDatabase(databaseName: "GetsAllAccounts") .Options; // Act using (var context = new AccountingContext(options)) { _service = new AccountService(context); foreach (var account in accountList) { _service.Add(account); } // Assert Assert.Equal(_service.GetAccounts(), accountList); } }
public async Task <IActionResult> Post([FromBody] AccountModel model) { if (model is null) { return(HandleUnprocessableEntity()); } var result = await _service.Add(model.Map <AccountModel, User>()); if (result.IsValid) { var claims = new Dictionary <string, string>(); claims.Add(ClaimTypes.Sid, result.Data.Id.ToString()); var token = new AccountResultModel() { Id = result.Data.Id, NickName = result.Data.NickName, Token = new JwtTokenBuilder(_config.SecretJwtKey, _config.CookieExpiresInMinutes, claims).Build().Value }; return(HandleResult(new ResultDataModel <AccountResultModel>() { Data = token })); } return(HandleResult(result)); }
public IActionResult Add(int id, decimal value) { var account = accountService.Add(accountRepository, id, value); account.Balance += value; return(new OkObjectResult(account)); }
public ActionResult <object> Post([FromBody] AccountViewModel user) { if (user == null) { var toSerialize = new MessageHelpers <AccountViewModel>() { Status = 404, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } else { try { var id = _accountService.Add(user); var toSerialize = new MessageHelpers <AccountViewModel>() { Status = 200, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } catch { var toSerialize = new MessageHelpers <AccountViewModel>() { Status = 502, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } } }
public ActionResult EditAccounts(EditAccountsModel model) { if (ModelState.IsValid) { var account = _acc.GetById(model.Id); if (account == null) { return(RedirectToAction("Index", new { message = "Thông tin đăng nhập không chính xác", messageType = "error" })); } var pro = _pro.GetById(account.ProfileId); if (pro == null) { return(RedirectToAction("Index", new { message = "Không tìm thấy thông tin tài khoản", messageType = "error" })); } pro.Address = model.Address; pro.CompanyCode = model.CompanyCode; pro.CompanyName = model.CompanyName; pro.Email = model.Email; pro.Phone = model.Phone; pro.Province = model.Province; pro.TaxAgencyCode = model.TaxAgencyCode; pro.TaxAgencyName = model.TaxAgencyName; if (!_pro.Update(pro)) { return(RedirectToAction("Index", new { message = "Có lỗi khi cập nhật thông tin người dùng. Vui lòng thử lại sau", messageType = "error" })); } account.CompanyCode = model.CompanyCode; account.CompanyName = model.CompanyName; account.Address = model.Address; account.BankAccount = model.BankAccount; account.Phone = model.Phone; account.Representative = model.Representative; if (!_acc.Add(account)) { return(RedirectToAction("Index", new { message = "Có lỗi khi cập nhật thông tin tài khoản. Vui lòng thử lại sau", messageType = "error" })); } return(RedirectToAction("Index", new { message = "Cập nhật thông tin tài khoản thành công", messageType = "info" })); } else { ViewBag.Province = model.ProvinceId; ViewBag.District = model.TaxAgencyCode; model.ListProvince = ListTaxAgency(); return(View(model)); } }
public HttpResponseMessage Add_Account(JObject jsonData) { var account = JEntity <Account> .Instance().Get_Entity(jsonData); return(new HttpResponseMessage { Content = new StringContent(AccountService.Add(account).JsonSerialize()) }); }
public IActionResult Create([FromBody] AccountViewModel account) { if (account == null) return BadRequest(); var id = _accountService.Add(account); return Created($"api/Account/{id}", id); //HTTP201 Resource created }
public ActionResult Create(AccountModel newAccount) { try { ActionResult result; if (ModelState.IsValid) { try { var acc = _accountSvc.GetByLoginName(newAccount.CompanyCode); if (acc != null) { ModelState.AddModelError(String.Empty, UserControllerResource.CreateAccountError.FormatWith("Tên đăng nhập đã tồn tại!")); result = View(); } else { var password = newAccount.Password; var salt = EntityUtils.GenerateRandomBytes(Constants.PasswordSaltLength); var pwdHash = EntityUtils.GetInputPasswordHash(password, salt); var account = new Account { Phone = newAccount.Phone, CompanyName = newAccount.CompanyName, CompanyCode = newAccount.CompanyCode, Status = 0, RoleCode = (byte)newAccount.Role, PasswordHash = pwdHash, PasswordSalt = salt, Permissions = 0 }; _accountSvc.Add(account); result = RedirectToAction("Me"); } } catch (Exception ex) { ModelState.AddModelError(String.Empty, UserControllerResource.CreateAccountError.FormatWith(ex.Message)); result = View(); } } else { ModelState.AddModelError(String.Empty, UserControllerResource.InvalidAccountInfo); result = View(); } return(result); } catch (Exception ex) { TempData.Add("error", ex.ToString()); return(RedirectToAction("Index", "Error")); } }
public static void AddAccount() { var bankAccount = new BankAccount(); var bankAccountFact = new BankAccountFact(); var accountService = new AccountService(bankAccountFact); Account acc1 = bankAccount.GetAccount(1, "Kirill", "Korzun", 12, 0, AccountType.Base); Account acc2 = bankAccount.GetAccount(2, "Oleg", "Olegovich", 200, 0, AccountType.Gold); Account acc3 = bankAccount.GetAccount(3, "Vasya", "Vasich", 0, 0, AccountType.Platinum); acc1.ReplenishmentMoney(2000); acc2.ReplenishmentMoney(123); accountService.Add(acc1); accountService.Add(acc2); accountService.Add(acc3); accountService.Save(); }
public ActionResult Index(AccountingViewModel AccountVM, int page = 1) { if (ModelState.IsValid) { _accountSvc.Add(AccountVM); _accountSvc.Save(); return(RedirectToAction("Index")); } return(View(AccountVM)); }
public ActionResult Create([Bind(Include = "AccountType,Total,CreateTime,Notes")] AccountViewModel account) { if (ModelState.IsValid) { _accountService.Add(account); _accountService.Save(); } ViewData["AccountTypes"] = GetAccountTypeList(); return(View(account)); }
public ActionResult Create([Bind(Include = "Id,Categoryyy,Amounttt,Dateee,Remarkkk")] AccountBook accountbook) { if (ModelState.IsValid) { _accService.Add(accountbook); _accService.Save(); //return RedirectToAction("Index"); return(View()); } return(View(accountbook)); }
public async Task <IActionResult> Register(RegisterModel registerModel) { if (ModelState.IsValid) { AccountService accountService = new AccountService(); var user = new UserModel() { Login = registerModel.Email, Password = registerModel.Password }; accountService.Add(user.ToBLL()); user = accountService.Login(registerModel.Email, registerModel.Password).ToView(); await Authenticate(user); return(RedirectToAction("Index", "Home")); } return(View(registerModel)); }
public void Save() { try { var IsSaved = ObjAccountService.Add(CurrentAccount); LoadData(); if (IsSaved) { Message = "Account saved"; } else { Message = "Save operation failed"; } } catch (Exception ex) { Message = ex.Message; } }
public void Service__AddsNewAccount() { // Arrange var id = 49203841098409218UL; var account = GetMockAccount(id, "test_value1", 123, 123, true); var options = new DbContextOptionsBuilder <AccountingContext>() .UseInMemoryDatabase(databaseName: "AddsNewAccount") .Options; // Act using (var context = new AccountingContext(options)) { _service = new AccountService(context); _service.Add(account); // Assert Assert.Equal(context.Accounts.Find(id), account); } }
public ActionResult Create(OAccount model) { if (ModelState.IsValid) { try { accountService.Add(model); return(RedirectToAction("Search", "QuanLyNguoiDung")); } catch (Exception e) { } } ViewBag.IsEdit = true; ViewBag.Customers = new SelectList(khService.GetAll(), "MaKhach", "TenKhach"); ViewBag.ListRoles = new SelectList(accountService.GetAllRole(), "MaQuyen", "TenQuyen"); return(View(model)); }
public ActionResult Create(UserModel user) { if (ModelState.IsValid) { AccountService accountService = new AccountService(); accountService.Add(user.ToBLL()); } var userService = new AccountService(); var users = userService.GetByCondition((x) => x.Role != null && x.Role.Name != "Customer"); UsersListModel usersListModel = new UsersListModel(); usersListModel.Users = new List <UserModel>(); foreach (var curUser in users) { usersListModel.Users.Add(curUser.ToView()); } return(View("Index", usersListModel)); }
private static void DbInitialize() { Role adminRole = new Role { Name = "Admin", ContentManager = true, UserAdmin = true, Seller = true, Сourier = true }; Role contentManager = new Role { Name = "ContentManager", ContentManager = true, UserAdmin = false, Seller = false, Сourier = false }; RoleService roleService = new RoleService(); roleService.Add(adminRole); roleService.Add(contentManager); roleService.Add(new Role { Name = "Courier", ContentManager = false, UserAdmin = false, Seller = false, Сourier = true }); roleService.Add(new Role { Name = "Seller", ContentManager = false, UserAdmin = false, Seller = true, Сourier = false }); roleService.Add(new Role { Name = "Customer", ContentManager = false, UserAdmin = false, Seller = false, Сourier = false }); //adminRole.Id = contentManager.Id = 0; //RoleService roleService = new RoleService(); //var adminRole = roleService.GetAll().FirstOrDefault(x => x.UserAdmin == true); //var contentManager = roleService.GetAll().FirstOrDefault(x => x.UserAdmin == false); User adminUser = new User { Login = "******", Password = "******", RoleId = adminRole.Id }; User contentUser = new User { Login = "******", Password = "******", RoleId = contentManager.Id }; AccountService accountService = new AccountService(); accountService.Add(adminUser); accountService.Add(contentUser); CarBrand renault = new CarBrand { Name = "Ranault", ImagePath = "test1" }; CarBrand citroen = new CarBrand { Name = "Citroen", ImagePath = "test2" }; CarBrand peugeot = new CarBrand { Name = "Peugeot", ImagePath = "test3" }; CarBrand bugatti = new CarBrand { Name = "Bugatti", ImagePath = "test4" }; CarBrandService carBrandService = new CarBrandService(); carBrandService.Add(renault); carBrandService.Add(citroen); carBrandService.Add(peugeot); carBrandService.Add(bugatti); CarModel logan = new CarModel { Name = "Logan", CarBrandId = renault.Id }; CarModel stepway = new CarModel { Name = "Stepway", CarBrandId = renault.Id }; CarModel kaptur = new CarModel { Name = "Kaptur", CarBrandId = renault.Id }; CarModel koleos = new CarModel { Name = "Koleos", CarBrandId = renault.Id }; CarModelService carModelService = new CarModelService(); carModelService.Add(logan); carModelService.Add(stepway); carModelService.Add(kaptur); carModelService.Add(koleos); Console.WriteLine("DB has been initialized"); }
// POST: api/Accounts public IHttpActionResult Post(Account account) { svc.Add(account); return(Ok()); }
public Task <IResultModel <Guid> > Add(AccountAddModel model) { return(_service.Add(model)); }