private static Connection MappConnectionDTO2Connection(ConnectionDTO conDTO) { Connection con = new Connection() { EndPlace = conDTO.EndPlace, Id = conDTO.Id, Version = conDTO.Version, Name = conDTO.Name, StartPlace = conDTO.StartPlace, Train = Mapper.Map <TrainDTO, Train>(conDTO.Train), Parts = new List <ConnectionPart>() }; foreach (var part in conDTO.Parts) { ConnectionPart conpart = new ConnectionPart() { EndTime = part.EndTime, FreeSeats = part.FreeSeats, Id = part.Id, Seats = part.Seats, StartTime = part.StartTime, Version = part.Version, Route = Mapper.Map <RouteDTO, Route>(part.Route), }; conpart.Connection = con; con.Parts.Add(conpart); } return(con); }
private static ConnectionDTO MappConnection2ConnectionDTO(Connection con) { ConnectionDTO conDTO = new ConnectionDTO() { EndPlace = con.EndPlace, Id = con.Id, Version = con.Version, Name = con.Name, StartPlace = con.StartPlace, Train = Mapper.Map <Train, TrainDTO>(con.Train), Parts = new List <ConnectionPartDTO>() }; foreach (var part in con.Parts) { ConnectionPartDTO conpart = new ConnectionPartDTO() { EndTime = part.EndTime, FreeSeats = part.FreeSeats, Id = part.Id, Seats = part.Seats, StartTime = part.StartTime, Version = part.Version, Route = Mapper.Map <Route, RouteDTO>(part.Route), }; conpart.Connection = conDTO; conDTO.Parts.Add(conpart); } return(conDTO); }
public void BuyTicketTest() { // Arrange var data = unitOfFactory.CreateTransactionalUnitOfWork(); User user = new User() { Login = "******", Password = "******", Tickets = "1,2,3:1-14,15,16;1,1,3,3:1-24,25,26,27" }; data.Users.Add(user); data.SaveChanges(); DiscountsController discountController = new DiscountsController(unitOfFactory); var discountResult = discountController.GetDiscount(1); var discount = (discountResult.Result as OkNegotiatedContentResult <DiscountDTO>).Content; Dictionary <DiscountDTO, int> dict = new Dictionary <DiscountDTO, int>(); dict.Add(discount, 2); ConnectionPathDTO conPath = new ConnectionPathDTO(); Connection con = data.Connections.Find(1); ConnectionDTO conDTO = Mapper.Map <Connection, ConnectionDTO>(con); ConnectionPart conPart = new ConnectionPart { Connection = con, Id = 9999999, Seats = "1;2;3", FreeSeats = 3, Route = data.Routes.Find(1), StartTime = DateTime.Now, EndTime = DateTime.Now.AddMinutes(30) }; data.ConnectionParts.Add(conPart); data.SaveChanges(); conPath.ConnectionsParts = new List <ConnectionPartDTO> { Mapper.Map <ConnectionPart, ConnectionPartDTO>(conPart) }; UserDTO userDTO = Mapper.Map <User, UserDTO>(data.Users.Where(u => u.Login == user.Login).First()); TicketDTO ticketDTO = new TicketDTO() { Discounts = dict, User = userDTO, ConnectionPath = conPath, Seats = new List <int[]> { new int[] { 1, 3 } } }; TicketsModel ticketsModel = new TicketsModel(); data.SaveChanges(); // Act ticketsModel.BuyTicket(ticketDTO, data); // Assert Assert.AreEqual("2", conPart.Seats); Assert.AreEqual(string.Format("1,2,3:1-14,15,16;1,1,3,3:1-24,25,26,27;1,1:{0}-1,3", conPart.Id), user.Tickets); }
public IConfigurationEngine Create(string applicationName, ConnectionDTO connection, int refreshTimerIntervalInMs) { var storageProvider = _storageProviderFactory.Create(connection); var cacheManager = _cacheManagerFactory.Create(Enums.CacheProviderType.MemoryCache); return(new ConfigurationEngine(storageProvider, cacheManager, applicationName, refreshTimerIntervalInMs)); }
public static void PostConnection(HttpClient client, Connection connection) { ConnectionDTO connectionDTO = Mapper.Map <Connection, ConnectionDTO>(connection); string request = "api/Connections"; var response = client.PostAsJsonAsync(request, connectionDTO).Result; response.EnsureSuccessStatusCode(); }
public async Task <IHttpActionResult> GetConnection(string id) { ConnectionDTO connection = new ConnectionDTO(await db.Connections.FindAsync(id)); if (connection.Id == null) { return(NotFound()); } return(Ok(connection)); }
public IConfigurationDataRepository Create(ConnectionDTO connectionDTO) { switch (connectionDTO.StorageProviderType) { case StorageProviderType.MongoDb: return(new MongoDbDataRepository(connectionDTO.ConnectionString)); case StorageProviderType.InMemoryDb: return(new InMemoryDataRepository()); default: throw new ArgumentOutOfRangeException(); } }
public IActionResult Create( [FromServices] IConnectionServices connectionServices, [FromBody] ConnectionDTO connectionDTO ) { var result = connectionServices.Create(connectionDTO); if (result.Success) { return(Ok(result)); } return(BadRequest()); }
public async Task <IHttpActionResult> GetConnection(int id) { using (var dbcontext = unitOfWorkFactory.CreateUnitOfWork()) { Connection connection = await Task.Run(() => dbcontext.Connections.Find(id)); if (connection == null) { return(NotFound()); } ConnectionDTO conDTO = AutoMapper.Mapper.Map <Connection, ConnectionDTO>(connection); return(Ok(conDTO)); } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { byte[] colBuff = new byte[3]; Random rand = new Random(); rand.NextBytes(colBuff); var info = value as SynchronizingConnection; var dto = new ConnectionDTO { Messages = info.ClientMessages, Color = Color.FromRgb(colBuff[0], colBuff[1], colBuff[2]), Id = rand.Next().ToString() }; return dto; }
public async Task <IHttpActionResult> PostConnection(ConnectionDTO connectionDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Connection connection = AutoMapper.Mapper.Map <ConnectionDTO, Connection>(connectionDTO); using (var dbcontext = unitOfWorkFactory.CreateUnitOfWork()) { dbcontext.Connections.Add(connection); await dbcontext.SaveChangesAsync(); connectionDTO = AutoMapper.Mapper.Map <Connection, ConnectionDTO>(connection); return(CreatedAtRoute("DefaultApi", new { id = connectionDTO.Id }, connectionDTO)); } }
public void OpenConnection(ConnectionDTO connection) { if (comPort.IsOpen) { comPort.Close(); } comPort.BaudRate = connection._baudrate; comPort.DataBits = connection._dataBits; comPort.Parity = connection._parity; comPort.StopBits = connection._stopBits; comPort.PortName = connection._port; comPort.Open(); _logger.Log(LogLevel.Trace, comPort.PortName + " opened"); }
private void do_login() { if (do_IsNotValid()) { return; } AppMain.User = new Models.Models.UsersDTO(); AppMain.User.password = txt_Password.Text; AppMain.User.username = txt_userCode.EditValue.ToString(); ConnectionDTO config = new ConnectionDTO { Database = "msp", //Global.SqlConnection.Database, Server = "DG", //Global.SqlConnection.Server, Password = "******", //Global.SqlConnection.Password, UserId = "sa" //Global.SqlConnection.UserId }; UserAuthDto model = new UserAuthDto { Config = config, User = AppMain.User }; var loginResponse = _repository.Run <AuthorizationService, ActionResponse <UsersDTO> >(x => x.LoginControl(model)); if (loginResponse.ResponseType != ResponseType.Ok) { DevExpress.XtraEditors.XtraMessageBox.Show(loginResponse.Message, "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Information); txt_Password.Focus(); return; } AppMain.User = loginResponse.Response; foreach (Form oForm in Application.OpenForms) { if (oForm.Name.Trim() == "MainFrm") { oForm.Text += "-" + this.lc_Company.Text.Trim() + "-" + AppMain.User.username; } } this.Close(); }
public ResultDTO Create(ConnectionDTO connectionDTO) { connectionDTO.Validate(); if (connectionDTO.Invalid) { return(new ResultDTO(false, "Invalid fields.", connectionDTO.Notifications)); } var connection = Connection.Create(connectionDTO.Id, connectionDTO.UserId); _connectionRepository.Create(connection); if (!_connectionRepository.Save()) { return(new ResultDTO(false, "Cannot be saved.", null)); } return(new ResultDTO(true, "Successfuly registered.", connection)); }
public void SetUp() { _uniqueId = new Mock <IUniqueIdService>(); _userMap = new Mock <IUserMapService>(); _notificationConnectionManager = new Mock <INotificationConnectionManager>(); _socket = new Mock <WebSocket>(); uniqueID = Guid.NewGuid(); notificationConnectionManager = new NotificationConnectionManager(_uniqueId.Object, _userMap.Object); userMap = new ConcurrentDictionary <string, HashSet <ConnectionDTO> >(); var hash = new HashSet <ConnectionDTO>(); var connectionDTO = new ConnectionDTO() { WebSocket = _socket.Object, ConnectionId = "1" }; hash.Add(connectionDTO); userMap.TryAdd("1", hash); }
public ActionResult Create(ConnectionDTO connectionDTO) { try { if (ModelState.IsValid) { connectionService.CreateConnection(connectionDTO.Server, connectionDTO.Database, connectionDTO.User, connectionDTO.Password); ViewBag.Message = "The process has been executed successfully"; ViewBag.Type = "info"; } } catch (Exception ex) { ViewBag.Message = ex.Message; ViewBag.Type = "danger"; } return(View(connectionDTO)); }
private void do_login() { if (do_IsNotValid()) { return; } AppMain.User = new Models.Models.UsersDTO(); AppMain.User.password = txt_Password.Text; AppMain.User.username = txt_userCode.EditValue.ToString(); var connection = applicationServers.FirstOrDefault(x => x.Id == (int)lc_serverList.EditValue); var config = new ConnectionDTO { Database = connection.DataBase, Server = connection.Server, Password = connection.Password, UserId = connection.UserName, localSql = AppMain.LocalConnect }; UserAuthDto model = new UserAuthDto { Config = config, User = AppMain.User }; var loginResponse = _repository.Run <AuthorizationService, ActionResponse <UsersDTO> >(x => x.LoginControl(model)); if (loginResponse.ResponseType != ResponseType.Ok) { DevExpress.XtraEditors.XtraMessageBox.Show(loginResponse.Message, "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Information); txt_Password.Focus(); return; } if (_ResetPassword.Checked == true) { ChangePassword oForm = new ChangePassword(); oForm.ShowDialog(); } AppMain.User = loginResponse.Response; AppMain.CompanyRecId = _company.Where(x => x.CompanyCode.Trim() == lc_Company.EditValue.ToString().Trim()).FirstOrDefault().RecId; AppMain.Company = lc_Company.Text; Registry.CurrentUser.OpenSubKey(@"Software\MSP", true).SetValue("LastUser", txt_userCode.Text.ToString()); //Registry.CurrentUser.OpenSubKey(@"Software\MSP", true).SetValue("LastDatabase", this.databaseLookUpEdit.EditValue.ToString().Trim()); Registry.CurrentUser.OpenSubKey(@"Software\MSP", true).SetValue("LastServer", this.lc_serverList.Text.Trim()); Registry.CurrentUser.OpenSubKey(@"Software\MSP", true).SetValue("LastServerId", this.lc_serverList.EditValue); Registry.CurrentUser.OpenSubKey(@"Software\MSP", true).SetValue("Company", this.lc_Company.EditValue); Registry.CurrentUser.OpenSubKey(@"Software\MSP", true).SetValue("BeniHatirla", this.chk_BeniHatirla.Checked); foreach (Form oForm in Application.OpenForms) { if (oForm.Name.Trim() == "MainFrm") { oForm.Text += "-" + this.lc_Company.Text.Trim() + "-" + AppMain.User.username; } } this.Close(); }