protected static List <T> GetDTOList <T>(ref SqlCommand sqlCmd) where T : DTOBase { List <T> dtoList = new List <T>(); try { sqlCmd.Connection.Open(); SqlDataReader sqlReader = sqlCmd.ExecuteReader(); if (sqlReader.HasRows) { DTOParser baseParser = DTOParserFactory.GetParser(typeof(T)); baseParser.PopulateOrdinals(sqlReader); while (sqlReader.Read()) { T currentDTO = null; currentDTO = (T)baseParser.PopulateDTO(sqlReader); dtoList.Add(currentDTO); } sqlReader.Close(); } } catch (Exception e) { throw e; } finally { sqlCmd.Connection.Close(); sqlCmd.Connection.Dispose(); } return(dtoList); }
public async Task <object> InsertUser([FromBody] UserDTO Reg) { try { var userExist = Db.User.Any(u => u.Email == Reg.Email); if (!userExist) { User UL = DTOParser.ParseFromDTO(Reg); UL.Id = Guid.NewGuid(); UL.Password = BCrypt.Net.BCrypt.HashPassword(Reg.Password); Db.User.Add(UL); Db.UserAttribute.Add(new UserAttribute { Id = Guid.NewGuid(), UserId = UL.Id, AttributeId = Constants.CustomerAccountTypeId }); Db.SaveChanges(); var emailResponse = await SendRegistrationEmail(UL); return(new Response { Status = "Success", Message = "User Saved Successfully." }); } } catch (Exception) { throw; } return(new Response { Status = "Error", Message = "User already exists." }); }
protected static T GetDTO <T>(ref SqlCommand sqlCmd) where T : DTOBase { T currentDTO = null; try { sqlCmd.Connection.Open(); SqlDataReader sqlReader = sqlCmd.ExecuteReader(); if (sqlReader.HasRows) { sqlReader.Read(); DTOParser baseParser = DTOParserFactory.GetParser(typeof(T)); baseParser.PopulateOrdinals(sqlReader); currentDTO = (T)baseParser.PopulateDTO(sqlReader); sqlReader.Close(); } else { return(null); } } catch (Exception e) { throw e; } finally { sqlCmd.Connection.Close(); sqlCmd.Connection.Dispose(); } return(currentDTO); }
// GetSingleDTO protected static T GetSingleDTO <T>(ref SqlCommand command) where T : DTOBase { T dto = null; try { command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); DTOParser parser = DTOParserFactory.GetParser(typeof(T)); parser.PopulateOrdinals(reader); dto = (T)parser.PopulateDTO(reader); reader.Close(); } else { // S'il n'y a pas de données, nous renvoyons null. dto = null; } } catch (Exception e) { throw new Exception("Error populating data", e); } finally { command.Connection.Close(); command.Connection.Dispose(); } // Renvoie le DTO, rempli soit avec des données soit avec null. return(dto); }
protected static List <T> GetDTOListJSON <T>(ref SqlCommand command) where T : CommonBase { List <T> dtoList = new List <T>(); try { command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { // Get a parser for this DTO type and populate // the ordinals. DTOParser parser = DTOParserFactory.GetParser(typeof(T)); parser.PopulateOrdinals(reader); while (reader.Read()) { dtoList = parser.PopulateDTOList <T>(reader); } reader.Close(); } } catch (SqlException oEx) { throw oEx; } finally { command.Connection.Close(); command.Connection.Dispose(); } return(dtoList); }
// GetSingleDTO protected static T GetSingleDTO <T>(ref SqlCommand command) where T : CommonBase { T dto = null; try { SqlDataReader reader; DTOParser parser = DTOParserFactory.GetParser(typeof(T)); command.CommandTimeout = 3000; //tamaño time out para enviar en el config command.Connection.Open(); reader = command.ExecuteReader(); if (reader.Read()) { parser.PopulateOrdinals(reader); dto = (T)parser.PopulateDTO(reader); reader.Close(); } } catch (SqlException oEx) { throw oEx; } finally { command.Connection.Close(); command.Connection.Dispose(); } // return the DTO, it's either populated with data or null. return(dto); }
public async Task <IActionResult> GetOrderDetails(string id) { if (string.IsNullOrWhiteSpace(id)) { return(BadRequest()); } else { var orderObject = await Db.Order .Include(o => o.User) .Include(o => o.FkBillingAddressNavigation) .Include(o => o.OrderAttribute) .ThenInclude(oa => oa.Attribute) .FirstOrDefaultAsync(o => o.Id == Guid.Parse(id)); var orderlinesObject = await Db.OrderLine .Include(ol => ol.Shape) .Include(ol => ol.Material) .Where(ol => ol.OrderId == orderObject.Id).ToListAsync(); var orderDetails = DTOParser.ParseToDTO(orderObject); var orderLines = DTOParser.ParseToDTO(orderlinesObject); return(Json(new { orderDetails, orderLines })); } }
public void ParseToDTO_Order_ValidValues_ShouldWork(Order order, OrderDTO expected) { var actual = DTOParser.ParseToDTO(order); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Price, actual.Price); Assert.Equal(expected.CreationDateTime, actual.CreationDateTime); Assert.Equal(expected.UserFullName, actual.UserFullName); }
public void ParseFromDTO_User_ValidValues_ShouldWork(UserDTO user, User expected) { var actual = DTOParser.ParseFromDTO(user); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Email, actual.Email); Assert.Equal(expected.FirstName, actual.FirstName); Assert.Equal(expected.LastName, actual.LastName); }
public ActionResult RegisterUser(UserDto dto) { if (!ModelState.IsValid) { return(View("Register")); } User user = null; user = DTOParser.Parse(dto, user); this.userService.Add(user); return(View("Login")); }
public void ParseToDTO_OrderLines_ValidValues_ShouldWork(List <OrderLine> orderLines, List <OrderLineDTO> expected) { var actual = DTOParser.ParseToDTO(orderLines); Assert.Equal(expected.Count, actual.Count); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i].ShapeId, actual[i].ShapeId); Assert.Equal(expected[i].ShapeName, actual[i].ShapeName); Assert.Equal(expected[i].ShapeWidth, actual[i].ShapeWidth); Assert.Equal(expected[i].ShapeHeight, actual[i].ShapeHeight); Assert.Equal(expected[i].MaterialId, actual[i].MaterialId); Assert.Equal(expected[i].MaterialName, actual[i].MaterialName); Assert.Equal(expected[i].Quantity, actual[i].Quantity); } }
// GetDTOList protected static List <T> GetDTOList <T>(ref SqlCommand command) where T : DTOBase { List <T> dtoList = new List <T>(); try { command.Connection.Open(); command.CommandTimeout = 3600; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { // Obtenir un analyseur (parser) pour ce type de DTO et remplir les ordinaux. DTOParser parser = DTOParserFactory.GetParser(typeof(T)); parser.PopulateOrdinals(reader); // Utilise l'analyseur (parser) pour construire notre liste de DTO. while (reader.Read()) { T dto = null; dto = (T)parser.PopulateDTO(reader); dtoList.Add(dto); } reader.Close(); } else { // S'il n'y a pas de données, nous renvoyons null. dtoList = null; } } catch (Exception e) { throw new Exception("Error populating data", e); } finally { command.Connection.Close(); command.Connection.Dispose(); } return(dtoList); }