public HuntsmanDto GetById(int huntsmanId) { using (var db = new DbContext()) { Entities.Huntsman huntsman = db.Huntsman.Find(huntsmanId); HuntsmanDto dto = ToDto(huntsman); return(dto); } }
private HuntsmanDto ToDto(Entities.Huntsman entity) { var dto = new HuntsmanDto { Id = entity.Id, Name = entity.Name, LastName = entity.LastName, Role = entity.Role }; return(dto); }
public int Insert(HuntsmanDto dto) { var entity = new Entities.Huntsman { Id = dto.Id, Name = dto.Name, LastName = dto.LastName, Role = dto.Role }; using (var db = new DbContext()) { Entities.Huntsman huntsman = db.Huntsman.Add(entity); db.SaveChanges(); return(huntsman.Id); } }
public UserDto Insert(string name, string lastName, string role, string email, string password) { using (var db = new DbContext()) { using (var transaction = db.Database.BeginTransaction()) { try { var huntsman = new Entities.Huntsman { Name = name, LastName = lastName, Role = role }; Entities.Huntsman newHuntsman = db.Huntsman.Add(huntsman); db.SaveChanges(); var user = new Entities.User { HuntsmanId = newHuntsman.Id, Email = email, Password = password, EmailVerified = false, ActivationCode = Guid.NewGuid().ToString(), ActivationCodeTimeStamp = DateTime.Now, CreationTimeStamp = DateTime.Now }; db.User.Add(user); db.SaveChanges(); transaction.Commit(); return(ToDto(user)); } catch (Exception ex) { transaction.Rollback(); return(null); } } } }