public JsonResult Update(string model) { bool status = false; //Ep kieu model string sang doi tuong JavaScriptSerializer serializer = new JavaScriptSerializer(); Employee employee = serializer.Deserialize <Employee>(model); //Lay ra employee can cap nhat var entity = db.Employees.Find(employee.ID); entity.Salary = employee.Salary; try { db.SaveChanges(); status = true; } catch { status = false; } return(Json(new { status = status, })); }
public static void AnalyseRide(ModelDataContext context, int userId, int rideId) { var speedAchievements = context.SpeedAchievement .Select(row => new MinSpeedAchievement { SpeedAchievementId = row.SpeedAchievementId, MinMph = row.MinMph, Name = row.Name, }) .ToList(); var jumpAchievements = context.JumpAchievement .Select(row => new MinJumpAchievement { JumpAchievementId = row.JumpAchievementId, MinAirtime = row.MinAirtime, Name = row.Name, }) .ToArray(); var rideLocations = AnalyserHelper.GetRideLocations(context, rideId); var rideJumps = AnalyserHelper.GetRideJumps(context, rideId); foreach (var speedAchievement in speedAchievements) { if (speedAchievement.Check(rideLocations)) { UserSpeedAchievement userSpeedAchievement = new UserSpeedAchievement { RideId = rideId, SpeedAchievementId = speedAchievement.SpeedAchievementId, UserId = userId, }; context.UserSpeedAchievement.Add(userSpeedAchievement); context.SaveChanges(); } } foreach (var jumpAchievement in jumpAchievements) { if (jumpAchievement.Check(rideJumps)) { UserJumpAchievement userJumpAchievement = new UserJumpAchievement { RideId = rideId, JumpAchievementId = jumpAchievement.JumpAchievementId, UserId = userId, }; context.UserJumpAchievement.Add(userJumpAchievement); context.SaveChanges(); } } }
private int SaveRide(int userId, CreateRideDto model) { var routeSvgPath = new SvgBuilder(model.Locations.Cast <ILatLng>()).Build(); Ride ride = new Ride(); ride.StartUtc = model.StartUtc; ride.EndUtc = model.EndUtc; ride.UserId = userId; ride.AverageSpeedMph = model.Locations.Average(i => i.Mph); ride.MaxSpeedMph = model.Locations.Max(i => i.Mph); ride.DistanceMiles = DistanceHelpers.GetDistanceMile(model.Locations.Cast <ILatLng>().ToList()); ride.RouteSvgPath = routeSvgPath; ride.RideLocations = model.Locations .Select(i => new RideLocation { AccuracyInMetres = i.AccuracyInMetres, Altitude = i.Altitude, Latitude = i.Latitude, Longitude = i.Longitude, Mph = i.Mph, Timestamp = i.Timestamp, }) .ToList(); ride.Jumps = model.Jumps .Select(i => new Jump { Airtime = i.Airtime, Number = i.Number, Timestamp = i.Timestamp, Latitude = i.Latitude, Longitude = i.Longitude, }) .ToList(); ride.AccelerometerReadings = model.AccelerometerReadings .Select(i => new AccelerometerReading { Time = i.Timestamp, X = i.X, Y = i.Y, Z = i.Z, }) .ToList(); context.Rides.Add(ride); context.SaveChanges(); return(ride.RideId); }
public int ConfirmaCorreo(string guid) { int result = 0; ModelDataContext db = new ModelDataContext(); try { db.ContextOptions.LazyLoadingEnabled = true; Guid g = new Guid(guid); UsuarioLinkPassword usr = db.UsuarioLinkPassword.SingleOrDefault(s => s.Link == g && s.Activo); if (usr != null) { usr.Usuario.Activo = true; usr.Activo = false; result = usr.Id; db.SaveChanges(); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } return(result); }
public void CreaiIncidencia(int idTipoIncidencia, int idUsuario, int idCancion, int?idGeneroSugerido, int?idArtistaSugerido, int?idAlbumSugerido, string nombreSugerido) { ModelDataContext db = new ModelDataContext(); try { Incidencia incidencia = new Incidencia { IdTipoIncidencia = idTipoIncidencia, IdUsuario = idUsuario, IdCancion = idCancion, IdGeneroSugerido = idGeneroSugerido, IdArtistaSugerido = idArtistaSugerido, IdAlbumSugerido = idAlbumSugerido, NombreCancionSugerido = nombreSugerido.ToUpper().Trim(), FechaIncidencia = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"), "yyyy-MM-dd HH:mm:ss:fff", CultureInfo.InvariantCulture) }; db.Incidencia.AddObject(incidencia); db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
public void GeneraSolicitudCancion(int idUsuario, string idGenero, string idArtista, string idAlbum, string cancion, string comentarios) { ModelDataContext db = new ModelDataContext(); try { Sugerencia sugerencia = new Sugerencia { IdUsuario = idUsuario, Genero = idGenero.Trim().ToUpper(), Artista = idArtista.Trim().ToUpper(), Album = idAlbum.Trim().ToUpper(), Cancion = cancion.Trim().ToUpper(), Comentarios = comentarios.Trim().ToUpper() }; db.Sugerencia.AddObject(sugerencia); db.SaveChanges(); BusinessCorreo.SendMail("*****@*****.**", "Solicitud de Cancion", string.Format("Genero: {0}\nArtista: {1}\nAlbum: {2}\nCanción: {3}\n Comentarios: {4}", sugerencia.Genero, sugerencia.Artista, sugerencia.Album, sugerencia.Cancion, sugerencia.Comentarios)); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
private static void CreateNewCountries(IEnumerable <CountryDto> newData) { using (ModelDataContext context = new ModelDataContext()) { var countryNames = context.Country .Select(row => row.Name) .ToList(); var newCountries = newData .Where(row => !countryNames.Contains(row.Name)) .ToList(); foreach (var country in newCountries) { Console.WriteLine($"Creating {country.Name}"); context.Country.Add(new Country { Name = country.Name, }); context.SaveChanges(); newCountryCount++; } } }
public void Analyse(ModelDataContext context, int userId, int rideId) { var speedAchievements = context.SpeedAchievements .Select(row => new MinSpeedAchievement { SpeedAchievementId = row.SpeedAchievementId, MinMph = row.MinMph, Name = row.Name, }) .ToList(); var speeds = context.RideLocations .Where(row => row.RideId == rideId) .Where(row => !row.IsRemoved) .Select(row => row.Mph) .ToList(); foreach (var speedAchievement in speedAchievements) { if (speedAchievement.Check(speeds)) { UserSpeedAchievement userSpeedAchievement = new UserSpeedAchievement { RideId = rideId, SpeedAchievementId = speedAchievement.SpeedAchievementId, UserId = userId, }; context.UserSpeedAchievements.Add(userSpeedAchievement); context.SaveChanges(); } } }
public void GeneraVisita(string ip) { if (ip.Trim() == string.Empty) { return; } ModelDataContext db = new ModelDataContext(); try { Visita visita = db.Visita.SingleOrDefault(s => s.Ip == ip); if (visita == null) { visita = new Visita { Ip = ip, Veces = 1 }; db.Visita.AddObject(visita); } else { visita.Veces += 1; } db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
public void Analyse(ModelDataContext context, int userId, int rideId) { var distanceAchievements = context.DistanceAchievements .Select(row => new MinDistanceAchievement { DistanceAchievementId = row.DistanceAchievementId, MinDistanceMiles = row.MinDistanceMiles, Name = row.Name, }) .ToList(); double distance = context.Rides .Where(row => row.RideId == rideId) .Select(row => row.DistanceMiles) .SingleOrDefault(); foreach (var distanceAchievement in distanceAchievements) { if (distanceAchievement.Check(distance)) { UserDistanceAchievement userDistanceAchievement = new UserDistanceAchievement { RideId = rideId, DistanceAchievementId = distanceAchievement.DistanceAchievementId, UserId = userId, }; context.UserDistanceAchievements.Add(userDistanceAchievement); context.SaveChanges(); } } }
public Usuario GetUserDataAutenticateId(int idUsuario, string ip) { Usuario result; ModelDataContext db = new ModelDataContext(); try { db.ContextOptions.ProxyCreationEnabled = _proxy; result = db.Usuario.SingleOrDefault(w => w.Id == idUsuario && w.Activo && w.Habilitado); if (result != null) { BitacoraAcceso nuevoAcceso = new BitacoraAcceso { IdUsuario = result.Id, Fecha = DateTime.Now, Ip = ip }; db.BitacoraAcceso.AddObject(nuevoAcceso); db.SaveChanges(); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } return(result); }
public void CrearCancion(int idAlbum, string nombreArchivo) { ModelDataContext db = new ModelDataContext(); try { Cancion newSong = new Cancion(); FileInfo fileInfo = new FileInfo(BusinessVariables.Directorios.RepositorioTemporal + nombreArchivo); BusinessFile.MoverTemporales(BusinessVariables.Directorios.RepositorioTemporal, BusinessVariables.Directorios.Repositorio, nombreArchivo); switch (fileInfo.Extension.ToLower()) { case ".mp3": newSong = new Cancion { IdAlbum = idAlbum, Descripcion = nombreArchivo, Extension = fileInfo.Extension, ContentType = "audio/mpeg3", FilePath = BusinessVariables.Directorios.Repositorio + nombreArchivo, Data = null }; break; case ".m4a": newSong = new Cancion { IdAlbum = idAlbum, Descripcion = nombreArchivo, Extension = fileInfo.Extension, ContentType = "audio/mpeg4", FilePath = BusinessVariables.Directorios.Repositorio + nombreArchivo, Data = null }; break; case ".m4b": newSong = new Cancion { IdAlbum = idAlbum, Descripcion = nombreArchivo, Extension = fileInfo.Extension, ContentType = "audio/mpeg4", FilePath = BusinessVariables.Directorios.Repositorio + nombreArchivo, Data = null }; break; } db.Cancion.AddObject(newSong); db.SaveChanges(); BusinessFile.LimpiarTemporales(nombreArchivo); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
public void Analyse(ModelDataContext context, int userId, int rideId) { var jumpAchievements = context.JumpAchievements .Select(row => new MinJumpAchievement { JumpAchievementId = row.JumpAchievementId, MinAirtime = row.MinAirtime, Name = row.Name, }) .ToArray(); var airtimes = context.Jumps .Where(row => row.RideId == rideId) .Select(row => row.Airtime) .ToList(); foreach (var jumpAchievement in jumpAchievements) { if (jumpAchievement.Check(airtimes)) { UserJumpAchievement userJumpAchievement = new UserJumpAchievement { RideId = rideId, JumpAchievementId = jumpAchievement.JumpAchievementId, UserId = userId, }; context.UserJumpAchievements.Add(userJumpAchievement); context.SaveChanges(); } } }
public void RecuperarCuenta(int idUsuario, int idTipoNotificacion, string link, string correo, string codigo, string contrasena, string tipoRecuperacion) { ModelDataContext db = new ModelDataContext(); try { switch (int.Parse(tipoRecuperacion)) { case 0: new BusinessUsuarios().ValidaCodigoVerificacionCorreo(idUsuario, idTipoNotificacion, link, correo, codigo); new BusinessUsuarios().TerminaCodigoVerificacionCorreo(idUsuario, idTipoNotificacion, link, correo, codigo); break; case 1: new BusinessUsuarios().ValidaCodigoVerificacionSms(idUsuario, idTipoNotificacion, 0, codigo); new BusinessUsuarios().TerminaCodigoVerificacionSms(idUsuario, idTipoNotificacion, 0, codigo); break; } string hashedPdw = Utils.SecurityUtils.CreateShaHash(contrasena); Usuario user = db.Usuario.SingleOrDefault(w => w.Id == idUsuario && w.Habilitado); if (user != null) { //ParametrosGenerales parametrosG = db.ParametrosGenerales.First(); //if (parametrosG.StrongPassword) //{ // if (db.ParametroPassword.First().CaducaPassword) // user.FechaUpdate = DateTime.ParseExact(DateTime.Now.AddDays(db.ParametroPassword.First().TiempoCaducidad).ToString("yyyy-MM-dd HH:mm:ss:fff"), "yyyy-MM-dd HH:mm:ss:fff", CultureInfo.InvariantCulture); // if (db.UsuarioPassword.Any(a => a.IdUsuario == idUsuario && a.Password == hashedPdw)) // throw new Exception("Contraseña antigua intente con una diferente"); //} user.Pwd = hashedPdw; user.PwdDes = contrasena; //user.UsuarioPassword = new List<UsuarioPassword> // { // new UsuarioPassword // { // Fecha = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"), "yyyy-MM-dd HH:mm:ss:fff", CultureInfo.InvariantCulture), // Password = SecurityUtils.CreateShaHash(contrasena) // } // }; db.SaveChanges(); } //LimpiaPasswordsAntiguos(idUsuario); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
private int SaveSegment(int userId, SegmentDto model) { Segment segment = new Segment { Name = model.Name, UserId = userId, }; segment.SegmentLocation = model.Locations .Select(i => new SegmentLocation { Latitude = i.Latitude, Longitude = i.Longitude, Order = i.Order, }) .ToList(); context.Segment.Add(segment); context.SaveChanges(); return(segment.SegmentId); }
private int SaveTrail(int userId, TrailDto model) { Trail trail = new Trail { Name = model.Name, UserId = userId, }; trail.TrailLocations = model.Locations .Select(i => new TrailLocation { Latitude = i.Latitude, Longitude = i.Longitude, Order = i.Order, }) .ToList(); context.Trails.Add(trail); context.SaveChanges(); return(trail.TrailId); }
public void CrearCuenta(string nombre, string apellido, string correo, string pwd) { ModelDataContext db = new ModelDataContext(); try { if (!ValidaCorreo(correo)) { throw new Exception("Correo ya se se encuentra en uso"); } if (db.Usuario.Any(a => a.Correo == correo.Trim().ToLower())) { throw new Exception("Ya se registro este correo"); } Usuario usr = new Usuario(); usr.Nombre = nombre.ToUpper(); usr.Apellido = apellido.ToUpper(); usr.Correo = correo.ToLower().Trim(); usr.Pwd = Utils.SecurityUtils.CreateShaHash(pwd); usr.PwdDes = pwd; usr.Sexo = true; usr.Activo = false; usr.FechaNacimiento = DateTime.Now; usr.FechaAlta = DateTime.Now; usr.Confirmado = false; usr.Habilitado = true; Guid g = Guid.NewGuid(); usr.UsuarioLinkPassword = new List <UsuarioLinkPassword> { new UsuarioLinkPassword { Activo = true, Link = g, Fecha = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"), "yyyy-MM-dd HH:mm:ss:fff", CultureInfo.InvariantCulture), IdTipoLink = (int)BusinessVariables.EnumeradoresStreaming.EnumTipoLink.Confirmacion } }; db.Usuario.AddObject(usr); db.SaveChanges(); BusinessFile.CreaRepositorio(usr.Correo); EnviaCorreo(usr.Nombre, usr.Correo, g.ToString()); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
public void Analyse(ModelDataContext context, int userId, int rideId) { var locations = context.RideLocations .Where(row => row.RideId == rideId) .ToList(); foreach (var location in locations) { if (location.AccuracyInMetres > 20) { location.IsRemoved = true; location.RemovalReason = "Accuracy"; } } context.SaveChanges(); }
public ActionResult UpdateBio(BioChangeDto bioModel) { int userId = this.GetCurrentUserId(); var user = context.Users.Find(userId); if (user == null) { return(NotFound()); } user.Bio = bioModel.Bio; context.SaveChanges(); return(Ok()); }
public string EnviaCodigoVerificacionCorreo(int idUsuario, int idTipoNotificacion) { ModelDataContext db = new ModelDataContext(); string result = null; try { db.ContextOptions.ProxyCreationEnabled = _proxy; Random generator = new Random(); String codigo = generator.Next(0, 99999).ToString("D5"); Guid g = Guid.NewGuid(); ParametroCorreo correo = db.ParametroCorreo.SingleOrDefault(s => s.IdTipoCorreo == (int)BusinessVariables.EnumeradoresStreaming.EnumTipoCorreo.RecuperarCuenta && s.Habilitado); if (correo != null) { db.LoadProperty(correo, "TipoCorreo"); Usuario usuario = db.Usuario.Single(u => u.Id == idUsuario); String body = string.Format(correo.Contenido, usuario.NombreCompleto, ConfigurationManager.AppSettings["siteUrl"] + "/FrmRecuperar.aspx?confirmacionCodigo=" + BusinessQueryString.Encrypt(idUsuario + "_" + g) + "&correo=" + BusinessQueryString.Encrypt(usuario.Correo) + "&code=" + BusinessQueryString.Encrypt(codigo), codigo); BusinessCorreo.SendMail(usuario.Correo, correo.TipoCorreo.Descripcion, body); usuario.UsuarioLinkPassword = new List <UsuarioLinkPassword> { new UsuarioLinkPassword { Activo = true, Link = g, Fecha = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"), "yyyy-MM-dd HH:mm:ss:fff", CultureInfo.InvariantCulture), IdTipoLink = (int)BusinessVariables.EnumeradoresStreaming.EnumTipoLink.Reset, Codigo = codigo } }; db.SaveChanges(); result = g.ToString(); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } return(result); }
public void CrearArtista(int idGenero, string descripcion) { ModelDataContext db = new ModelDataContext(); try { db.Artista.AddObject(new Artista { IdGenero = idGenero, Descripcion = descripcion.ToUpper().Trim(), Habilitado = true }); db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
public void CrearLista(string descripcion, int idUsuario) { ModelDataContext db = new ModelDataContext(); try { db.ListaReproduccion.AddObject(new ListaReproduccion { IdUsuario = idUsuario, Descripcion = descripcion.ToUpper().Trim(), Habilitada = true }); db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
private void Analyse(ModelDataContext context, int userId, RideDto ride, IEnumerable <TrailAnalysis> trails) { var results = Analyse(ride, trails); foreach (var result in results) { TrailAttempt attempt = new TrailAttempt { RideId = ride.RideId.Value, TrailId = result.TrailId, UserId = userId, StartUtc = ride.Locations[result.StartIdx].Timestamp, EndUtc = ride.Locations[result.EndIdx].Timestamp, }; attempt.Medal = (int)GetMedal(context, attempt.EndUtc - attempt.StartUtc, result.TrailId); context.TrailAttempts.Add(attempt); context.SaveChanges(); } }
public void CrearGenero(string descripcion) { ModelDataContext db = new ModelDataContext(); try { db.Genero.AddObject(new Genero { Descripcion = descripcion.ToUpper().Trim() }); db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
public void CrearAlbum(int idArtista, string descripcion) { ModelDataContext db = new ModelDataContext(); try { db.Album.AddObject(new Album { IdArtista = idArtista, Descripcion = descripcion.ToUpper().Trim() }); db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
private static void UpdateCurrentTotals() { using (ModelDataContext context = new ModelDataContext()) { var countries = context.Country.ToList(); foreach (var country in countries) { var lastRecord = context.Record .Where(row => row.CountryId == country.CountryId) .OrderByDescending(row => row.Date) .FirstOrDefault(); country.CurrentConfirmed = lastRecord?.Confirmed ?? 0; country.CurrentDeaths = lastRecord?.Deaths ?? 0; country.CurrentRecovered = lastRecord?.Recovered ?? 0; context.SaveChanges(); } } Console.WriteLine("Current totals updated"); }
public void AgregarCancionLista(int idListaReproduccion, int idCancion) { ModelDataContext db = new ModelDataContext(); try { ListaReproduccionDetalle detalle = new ListaReproduccionDetalle { IdListaReproduccion = idListaReproduccion, IdCancion = idCancion }; db.ListaReproduccionDetalle.AddObject(detalle); db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } }
public MainWindow() { InitializeComponent(); DataContext = new MainViewModel(); using (var db = new ModelDataContext()) { try { if (!db.Users.Any()) { db.Users.Add(new User { EMail = "*****@*****.**", Login = "******", Password = "******" }); db.SaveChanges(); } } catch (Exception e) { //db.Database.Delete(); db.Database.CreateIfNotExists(); } } }
public Usuario GetUserDataAutenticate(string user, string password, string ip) { Usuario result; ModelDataContext db = new ModelDataContext(); try { db.ContextOptions.ProxyCreationEnabled = _proxy; string hashedPdw = Utils.SecurityUtils.CreateShaHash(password); if (db.Usuario.Count(w => w.Correo == user && w.Pwd == hashedPdw && w.Habilitado && w.Activo) > 1) { throw new Exception("Error al obtener informacion consulte a su Administrador"); } result = db.Usuario.SingleOrDefault(w => w.Correo == user && w.Pwd == hashedPdw); if (result != null) { BitacoraAcceso nuevoAcceso = new BitacoraAcceso { IdUsuario = result.Id, Fecha = DateTime.Now, Ip = ip }; db.BitacoraAcceso.AddObject(nuevoAcceso); db.SaveChanges(); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } return(result); }
private static void Analyse(ModelDataContext context, int userId, int rideId, int segmentId) { var segmentLocations = AnalyserHelper.GetSegmentLocations(context, segmentId); var rideLocations = AnalyserHelper.GetRideLocations(context, rideId); var rideJumps = AnalyserHelper.GetRideJumps(context, rideId); var result = LocationsMatch(segmentLocations.Cast <ILatLng>().ToList(), rideLocations.Cast <ILatLng>().ToList()); if (result.MatchesSegment) { SegmentAttempt attempt = new SegmentAttempt { RideId = rideId, SegmentId = segmentId, UserId = userId, StartUtc = rideLocations[result.StartIdx].Timestamp, EndUtc = rideLocations[result.EndIdx].Timestamp, }; attempt.Medal = (int)GetMedal(context, attempt.EndUtc - attempt.StartUtc, segmentId); context.SegmentAttempt.Add(attempt); context.SaveChanges(); var locations = rideLocations[result.StartIdx..result.EndIdx]