public async Task <ActionResult> Create(ClientCreateModel model) { if (ModelState.IsValid) { CreateClientCommand createClientCommand = model.ToCreateClientCommand(); createClientCommand.CreatedBy = User.Identity.Name; createClientCommand.CreatedOn = DateTime.Now; int result = await Mediator.Send(createClientCommand); if (result > 0) { return(View("List")); } else { ModelState.AddModelError("", "Thêm Client thất bại"); } } model.AvailableClaims = await GetClaims(); model.AvailableScopes = await GetScopes(); model.InitData(); return(View(model)); }
public async Task <IActionResult> CreateNew(ClientCreateModel model) { if (!ModelState.IsValid) { ViewBag.Message = string.Format("Please correct the validation errors below.", model.ClientId); return(View("Create", model)); } model.ExistingClient = await _clientService.Find(model.ClientId); if (model.ExistingClient != null) { ViewBag.Message = string.Format("The Auth Central Client with ClientId {0} already exists. Please use a different and unique clientId.", model.ClientId); return(View("Create", model)); } Client client = model.ToNewClient(); if (!String.IsNullOrWhiteSpace(model.RedirectUri)) { client.RedirectUris.Add(model.RedirectUri); } if (!String.IsNullOrWhiteSpace(model.PostLogoutUri)) { client.PostLogoutRedirectUris.Add(model.PostLogoutUri); } await PersistClient(client); return(RedirectToAction("Edit", model)); }
public void CreatePost_Test() { ClientCreateModel cm = new ClientCreateModel(); cm.Data = new Client(); string randomName = System.IO.Path.GetRandomFileName(); cm.Data.FirstName = randomName; cm.Data.LastName = "last"; cm.Data.City = "city"; cm.Data.Address = "address"; cm.Data.AgencyId = new ccEntities().Agencies.First().Id; cm.Data.CountryId = new ccEntities().Countries.First().Id; cm.Data.JoinDate = DateTime.Now; ActionResult actual = Target.Create(cm); ccEntities context = new ccEntities(); Client newClient = context.Clients.Single(x => x.FirstName == randomName); Assert.IsNotNull(newClient == null, "new client was not created"); Assert.IsTrue(newClient.City == "city", "new client city was not saved"); }
public async Task AddAsync(ClientCreateModel model) { var client = new Client { Id = Guid.NewGuid(), Name = model.Name }; await _repository.AddAsync(client); }
public IActionResult Create() { var client = new ClientCreateModel { LogoUri = "https://fsw-res-1.cloudinary.com/d_noimage.jpg,h_69,w_160,c_fill/logos/fsw-logo.svg", SecretExpiration = new DateTimeOffset(DateTime.UtcNow.AddYears(1)) }; return(View(client)); }
public static void CreateClient(ClientCreateModel clm) { using (var sctx = new ShopContext()) { var cl = new DataAccess.Client { Name = clm.Name }; sctx.Clients.Add(cl); sctx.SaveChanges(); } }
public async Task <bool> Create(ClientCreateModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var user = new UserLoginData { UserName = model.CardNumber.Replace(" ", string.Empty), Email = model.Email, IsActive = true, OriginUsername = model.CardNumber }; var password = System.Web.Security.Membership.GeneratePassword(8, 2); var result = await _userManager.CreateAsync(user, password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user.Id, _roleService.GetClientRole().Name); var configuration = _clientConfigurationService.GetClientConfiguration(model.ConfigurationGroup); var client = new Client { FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, Email = model.Email, Address = model.Address, City = model.City, ClientId = user.Id, ClientConfigurationGroupId = configuration.Id }; _context.Clients.Add(client); await _context.SaveChangesAsync(); await _emailService.SendTemplateEmail(model.Email, "Registracija", "RegistrationEmail", new UserRegisterEmailModel { FirstName = model.FirstName, LastName = model.LastName, Password = password, UserName = user.UserName }); return(true); } return(false); }
public async Task <IActionResult> Create(ClientCreateModel clientModel) { if (!ModelState.IsValid) { return(View()); } HttpResponseMessage response = await httpClient.PostAsJsonAsync(ClientsAPIEndpoint, clientModel); Client client = await response.Content.ReadAsAsync <Client>(); return(RedirectToAction(nameof(ClientsController.Details), "Clients", new { id = client.Id })); }
public static void UpdateClient(int clientId, ClientCreateModel clm) { using (var sctx = new ShopContext()) { var curClient = sctx.Clients.SingleOrDefault(cl => cl.Id == clientId); if (curClient == null) { throw new Exception("There is no client with this ID"); } curClient.Name = clm.Name; sctx.SaveChanges(); } }
public static ClientCreateModel GetClient(int clientId) { using (var sctx = new ShopContext()) { var curClient = sctx.Clients.SingleOrDefault(cl => cl.Id == clientId); if (curClient == null) { throw new Exception("There is no client with this ID"); } var model = new ClientCreateModel() { Name = curClient.Name }; return(model); } }
public bool CreateClient(ClientCreateModel user) { int recordsInserted = this.ExecuteNonQuery( @"INSERT INTO Clients (Username, Name, PasswordHash, PasswordSalt, ClientTypeId) VALUES (@username, @name, @passwordHash, @passwordSalt, @clientTypeId)", new Dictionary <string, object>() { { "@username", user.Username }, { "@name", user.Name }, { "@passwordHash", user.PasswordHash }, { "@passwordSalt", user.PasswordSalt }, { "@clientTypeId", user.ClientTypeId } }); return(recordsInserted > 0); }
public async Task <ActionResult> Create() { var response = await _httpClientService.GetJsonContent("api/maintenance/adminsettings"); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsAsync <MaintenanceEditModel>(); var model = new ClientCreateModel { }; return(PartialView("_Create", model: model)); } return(HttpNotFound()); }
public async Task <IHttpActionResult> Create([FromBody] ClientCreateModel model) { if (!ModelState.IsValid) { return(Content(HttpStatusCode.BadRequest, GetValidationErrors())); } var result = await _clientService.Create(model); if (result) { _loggerService.Log(UserId, ActionType.Create, $"Cliend account created - {model.CardNumber}"); return(Ok()); } return(InternalServerError()); }
public bool CreateClient(ClientCreateModel client) { using (this.clientRepository) { bool isClientWithSameUsernameExisting = this.clientRepository.IsClientWithSameUsernameExisting(client.Username); if (isClientWithSameUsernameExisting) { return(false); } string passwordSalt = PasswordUtilities.GeneratePasswordSalt(); string passwordHash = PasswordUtilities.GeneratePasswordHash(client.Password, passwordSalt); client.PasswordHash = passwordHash; client.PasswordSalt = passwordSalt; bool createClientResult = this.clientRepository.CreateClient(client); return(createClientResult); } }
public async Task <IActionResult> Register(ClientCreateModel model) { if (ModelState.IsValid) { var cmd = new RegisterClientCommand(model.Name, model.Website, model.Description); var result = await _mediator.Send(cmd); if (result.IsFailure) { ModelState.AddModelError("", result.Error); } else { return(RedirectToAction(nameof(ClientController.Index))); } } return(View(model)); }
public async Task <ActionResult> Create(ClientCreateModel model) { if (!ModelState.IsValid) { return(PartialView("_Create", model: model)); } var response = await _httpClientService.SendRequest("api/clients/create", HttpMethod.Post, model); if (response.IsSuccessStatusCode) { return(NotificationSuccessResult(Resource.RecordEditSuccess, Url.RouteUrl(ClientRoutes.Data))); } var errorMessage = await _commonService.CheckForValidationErrors(response, Resource.ApplicationErrorText); ModelState.AddModelError(string.Empty, errorMessage); return(PartialView("_Create", model: model)); }
public async Task <IActionResult> Create([FromForm] ClientCreateModel model) { if (ModelState.IsValid) { var client = new Client { ClientId = model.ClientId, ClientName = model.ClientName, AllowedGrantTypes = GrantTypes.HybridAndClientCredentials, ClientSecrets = { new Secret(model.ClientSecret.Sha256()) }, RedirectUris = { model.IpAddress + "/signin-oidc" }, PostLogoutRedirectUris = { model.IpAddress + "/signout-callback-oidc" }, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile }, AllowOfflineAccess = true }; foreach (var item in model.ApiServices.Split(' ')) { client.AllowedScopes.Add(item); } await _context.Clients.AddAsync(client.ToEntity()); await _context.SaveChangesAsync(); return(Redirect("/Clients")); } return(View(model)); }
public ActionResult Register(ClientRegisterBindingModel clientModel) { if (!this.ModelState.IsValid) { clientModel = this.PrepareClientRegisterBindingModel(); return(this.View(clientModel)); } ClientCreateModel client = new ClientCreateModel(clientModel.Username, clientModel.Name, clientModel.Password, clientModel.ClientTypeId); bool registerResult = this.clientManager.CreateClient(client); if (!registerResult) { this.TempData.Add(TempDataErrorMessageKey, UserExistingUsername); return(this.RedirectToAction(nameof(ClientsController.Register), Clients)); } this.TempData.Add(TempDataSuccessMessageKey, RegistrationSuccessful); return(RedirectToAction(nameof(ClientsController.Login), Clients)); }
public async Task <ActionResult> Create() { ClientCreateModel model = new ClientCreateModel { RequireConsent = true, AllowRememberConsent = true, LogoutSessionRequired = true, AllowedCustomGrantTypes = true, EnableLocalLogin = true, PrefixClientClaims = true, IdentityTokenLifetime = 300, AccessTokenLifetime = 3600, AuthorizationCodeLifetime = 300, AbsoluteRefreshTokenLifetime = 2592000, SlidingRefreshTokenLifetime = 1296000 }; model.AvailableClaims = await GetClaims(); model.AvailableScopes = await GetScopes(); return(View(model)); }
public async Task Example2() { string address = "http://localhost:9000/"; using (WebApp.Start <WebAPI.Startup>(address)) { var clientModel = new ClientCreateModel() { Name = "First Client" }; var customerModel = new CustomerCreateModel() { Ammount = 1000, Nickname = "Alex" }; var itemModel = new ClientItemCreateModel() { Code = "asd", Name = "Emperor's sword", Price = 500 }; var clientUrl = new Url(address + "clients"); var resp = await clientUrl.PostJsonAsync(clientModel); Console.WriteLine(resp); //ClientService.CreateClient(clientModel); var customerUrl = new Url(address + "clients/customers").SetQueryParams(new { clientId = 1, model = customerModel }); var resp3 = await customerUrl.PostAsync(new HttpMessageContent(new HttpRequestMessage())); Console.WriteLine(resp3); var itemUrl = new Url(address + "clients/items"); var resp2 = await itemUrl.PostJsonAsync(new { clientId = 1, model = itemModel }); Console.WriteLine(resp2); } }
public void CreatePost_Test() { ClientCreateModel cm = new ClientCreateModel(); cm.Data = new Client(); string randomName = System.IO.Path.GetRandomFileName(); cm.Data.FirstName = randomName; cm.Data.LastName = "last"; cm.Data.City = "city"; cm.Data.Address = "address"; cm.Data.AgencyId = new ccEntities().Agencies.First().Id; cm.Data.CountryId = new ccEntities().Countries.First().Id; cm.Data.JoinDate = DateTime.Now; ActionResult actual = Target.Create(cm); Assert.IsNotNull(actual, "action result can not be null"); string actionName = (((System.Web.Mvc.RedirectToRouteResult)(actual))).RouteValues["action"].ToString(); Assert.IsTrue(actionName == "Index", "Regional Officer can not create new clients"); }
public static CreateClientCommand ToCreateClientCommand(this ClientCreateModel model) { return(model.MapTo <ClientCreateModel, CreateClientCommand>()); }
public void InitializeDatabase(COAssistanceDbContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var roleService = UnityConfig.Container.Resolve <IRoleService>(); var clientService = UnityConfig.Container.Resolve <IClientService>(); var userService = UnityConfig.Container.Resolve <IUserService>(); var clientConfigurationService = UnityConfig.Container.Resolve <IClientConfigurationService>(); var applicationUserManager = UnityConfig.Container.Resolve <ApplicationUserManager>(); var adminRole = roleService.GetAdminRole(); var clientRole = roleService.GetClientRole(); var clientConfiguration = clientConfigurationService.GetClientConfiguration(COMMONS.Models.ConfigurationGroupEnum.CO); if (!context.Admin.Any()) { var maintenanceId = GetMaintenanceId(context); var userToInsert = new UserLoginData { UserName = "******", OriginUsername = "******", IsActive = true, Email = "*****@*****.**" }; var admin = new Admin { FirstName = "Admin", LastName = "Sistema", MaintenanceId = maintenanceId }; bool isSuccess = applicationUserManager.CreateAsync(userToInsert, "Password!1").Result.Succeeded; if (!isSuccess) { throw new Exception("Initialization failed"); } admin.AdminId = userToInsert.Id; applicationUserManager.AddToRole(userToInsert.Id, EntityRoles.AdminRole); context.Admin.Add(admin); context.SaveChanges(); } if (!context.Clients.Any()) { var client = new ClientCreateModel { CardNumber = "000 210", Email = "*****@*****.**", FirstName = "Client", LastName = "Sistema", PhoneNumber = "+38763103730", Address = "Adresa", City = "Grad", ConfigurationGroup = ConfigurationGroupEnum.CO }; clientService.Create(client); } if (!context.OAuthClients.Any()) { var clients = BuildClientsList(adminRole, clientRole); context.OAuthClients.AddRange(clients); context.SaveChanges(); } }
public void UpdateClient(int clientId, ClientCreateModel clientCreateModel) { ClientService.UpdateClient(clientId, clientCreateModel); }
public void CreateClient(ClientCreateModel clientCreateModel) { ClientService.CreateClient(clientCreateModel); }