public List <Trainer> GetTrainerByLocation(string location) { using (GymContext db = new GymContext()) { List <Trainer> trainerList = new List <Trainer>(); var trainers = db.Trainers.OrderBy(l => l.ID).Select(l => new Trainer { ID = l.ID, TrainerName = l.TrainerName, Phone = l.Phone, Rating = l.Rating, Email = l.Email, Gender = l.Gender, Price = l.Price, Timeslots = l.Timeslots }); foreach (var trainer in trainers) { var trainerTimeslots = trainer.Timeslots; foreach (var trainerTimeslot in trainerTimeslots) { if (trainerTimeslot.Location.ToUpper() == location.ToUpper()) { trainerList.Add(trainer); } } } Console.WriteLine("\nTrainers:"); return(trainerList); } }
public static bool CancelMemberBooking(int classId, int memberId, GymContext db) { GymClass cl = db.GymClass.Find(classId); if (cl == null) { return(false); } var booking = db.MemberClassBookings.Where(bk => bk.GymClassId == cl.GymClassId && bk.GymMemberId == memberId).FirstOrDefault(); if (booking == null) { return(false); } db.Entry(booking).State = EntityState.Deleted; var nBookings = db.MemberClassBookings.Where(cls => cls.GymClassId == classId && !cls.Waiting).Count(); // Promote the next one from the waiting list GymClassBooking promotedBooking = null; if (!booking.Waiting && nBookings <= cl.MaxCapacity) { promotedBooking = db.MemberClassBookings.Where(bk => bk.GymClassId == cl.GymClassId && bk.Waiting == true).FirstOrDefault(); } if (promotedBooking != null) { promotedBooking.Waiting = false; db.Entry(promotedBooking).State = EntityState.Modified; } db.SaveChanges(); return(true); }
public async Task <ActionResult> UpdateGymProfile(GymContext gym, string[] selectedExpertises) { gym.Expertise = selectedExpertises; var result = await registerManager.SaveGym(gym); return(RedirectToAction("Index", "Home", new { area = "" })); }
public bool Eliminar(string id) { try { using (unitOfWork = new UnitOfWork(new GymContext())) { using (GymContext Context = new GymContext()) { InstructorGym per = new InstructorGym(); List <InstructorGym> p = Context.InstructorGyms.Select(n => n).Where(l => l.idInstructor == id).ToList(); foreach (InstructorGym pe in p) { List <LogUsuario> pp = Context.LogUsuarios.Select(n => n).Where(l => l.usuario == pe.usuario).ToList(); Context.InstructorGyms.Remove(pe); Context.SaveChanges(); foreach (LogUsuario pee in pp) { Context.LogUsuarios.Remove(pee); Context.SaveChanges(); } } } return(true); } } catch (Exception e) { string a = e.Message; return(false); } }
public bool Crear(string empresa, string cierre) { try { using (unitOfWork = new UnitOfWork(new GymContext())) { using (GymContext Context = new GymContext()) { List <Producto> p = Context.Productoes.Select(n => n).Where(l => l.idNombreEmpresa == empresa).ToList(); foreach (Producto pro in p) { string id = ConsecutivoModifica("CRM"); CierreProducto cp = new CierreProducto() { idProducto = pro.idProducto, idCierre = cierre, idNombreEmpresa = empresa, cantidadCierre = pro.cantidad, idCierreProducto = id }; unitOfWork.cierreProductoDAL.Add(cp); unitOfWork.Complete(); } } } return(true); } catch (Exception a) { string e = a.Message; return(false); } }
// Encryption key commented out until bonus functionality for the project has been completed. //public string Decrypt(string cipherText) //{ // string EncryptionKey = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // cipherText = cipherText.Replace(" ", "+"); // byte[] cipherBytes = Convert.FromBase64String(cipherText); // using (Aes encryptor = Aes.Create()) // { // Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { // 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 // }); // encryptor.Key = pdb.GetBytes(32); // encryptor.IV = pdb.GetBytes(16); // using (MemoryStream ms = new MemoryStream()) // { // using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)) // { // cs.Write(cipherBytes, 0, cipherBytes.Length); // cs.Close(); // } // cipherText = Encoding.Unicode.GetString(ms.ToArray()); // } // } // return cipherText; //} public bool Login(string username, string password) { using var db = new GymContext(); { User selectedUser = db.Users.Where(u => u.UserName == username).FirstOrDefault(); var details = (from user in db.Users where user.UserName == username select new { user.UserId, user.FirstName, user.LastName, user.Email }).ToList(); if (details.FirstOrDefault() != null && selectedUser.Password == password) { int currentUserId = details.FirstOrDefault().UserId; string currentFirstName = details.FirstOrDefault().FirstName; string currentLastName = details.FirstOrDefault().LastName; string currentEmail = details.FirstOrDefault().Email; GetCurrentUser(currentUserId, currentFirstName, currentLastName, currentEmail); return(true); } return(false); } }
public void ObtenerAlEntrenadorPorCodigo() { var ctx = new GymContext(); var entrenador = ctx.TBENTRENADORs.Find("70405060"); Assert.IsNotNull(entrenador); }
public void ObtenerListaDeClasesPorNombreAscendiente() { using (var ctx = new GymContext()) { var clases = ctx.TBCLASEs.OrderBy(s => s.NombreClase).ToList(); } }
public bool Eliminar(string id) { try { using (unitOfWork = new UnitOfWork(new GymContext())) { using (GymContext Context = new GymContext()) { List <PersonaMedidasGym> p = Context.PersonaMedidasGyms.Select(n => n).Where(l => l.idPersona == id).ToList(); foreach (PersonaMedidasGym pe in p) { Context.PersonaMedidasGyms.Remove(pe); Context.SaveChanges(); } PersonaGym per = new PersonaGym(); List <PersonaGym> pee = Context.PersonaGyms.Select(n => n).Where(l => l.idPersona == id).ToList(); foreach (PersonaGym pe in pee) { Context.PersonaGyms.Remove(pe); Context.SaveChanges(); } } return(true); } } catch (Exception e) { string a = e.Message; return(false); } }
public string[] getUser(string userName, string password) { using (GymContext con = new GymContext()) { try { var usu = con.LogUsuarios.Where(x => x.usuario.Equals(userName) && x.pass.Equals(password)).ToList(); var count = usu.Count(); if (count == 1) { string[] respuesta = new string[2]; foreach (var us in usu) { respuesta[0] = us.usuario; respuesta[1] = us.permiso; } return(respuesta); } else { return(null); } } catch (Exception e) { string a = e.Message; return(null); } } }
public ActionResult AssignRoleToUser1() { GymContext db = new GymContext(); int userId = Convert.ToInt32(Request.Form["Users"]); int roleId = Convert.ToInt32(Request.Form["Roles"]); String username = db.Users.Single(x => x.Id == userId).UserName; String rolename = db.Role.Single(x => x.RoleId == roleId).RoleName; if (roleId == 0) { ModelState.AddModelError("RoleName", "Please select RoleName"); } if (userId == 0) { ModelState.AddModelError("UserName", "Please select Username"); } if (Roles.IsUserInRole(username, rolename) == true) { ViewBag.ResultMessage = "This user already has the role specified !"; } else { Roles.AddUserToRole(username, rolename); ViewBag.ResultMessage = "User added to the role succesfully !"; } ViewBag.Users = new SelectList(db.Users, "Id", "UserName"); ViewBag.Roles = new SelectList(db.Role, "RoleId", "RoleName"); return(View()); }
public static Gym ConvertToGym(this GymContext context) { return(new Gym { Id = ObjectId.Parse(context.Id.ToString()), UserName = context.UserName, UserType = context.UserType, Created = context.Created, IsActive = context.IsActive, Email = context.Email, Description = context.Description, Location = context.Location.ConvertToLocation(), Modified = context.Modified, Password = context.Password, PhoneNumber = context.PhoneNumber, PhoneVisibility = context.PhoneVisibility, UserVisibility = context.UserVisibility, ExperienceYears = context.ExperienceYears, Expertise = context.Expertise, ParkingLot = context.ParkingLot, Price = context.Price, Showers = context.Showers, Reputation = context.Reputation, Birthday = context.Birthday, Name = context.Name }); }
public static GymContext ConvertToGymContext(this IGym gym) { GymContext context = new GymContext(); context.Id = gym.Id.ToString(); context.UserName = gym.UserName; context.UserType = gym.UserType; context.Created = gym.Created; context.IsActive = gym.IsActive; context.Email = gym.Email; context.Description = gym.Description; context.Location = gym.Location.ConvertToLocationContext(); context.Modified = gym.Modified; context.Password = gym.Password; context.PhoneNumber = gym.PhoneNumber; context.PhoneVisibility = gym.PhoneVisibility; context.UserVisibility = gym.UserVisibility; context.ExperienceYears = gym.ExperienceYears; context.Expertise = gym.Expertise; context.ParkingLot = gym.ParkingLot; context.Price = gym.Price; context.Showers = gym.Showers; context.Reputation = gym.Reputation; context.Name = gym.Name; context.Birthday = gym.Birthday; return(context); }
public async Task <UserGymProfileDataContext> ViewGymProfile(string userId) { GymContext gymContext = await GetById(userId); UserGymProfileDataContext gymProfileData = gymContext.ConvertToUserProfileContext(); return(gymProfileData); }
//[ValidateAntiForgeryToken] public ActionResult GetAllUsers() { GymContext db = new GymContext(); List <Users> users = db.Users.ToList(); return(View(users)); }
public HomeController(ILogger <HomeController> logger, GymContext content, IConfiguration config) { _logger = logger; db = content; configuration = config; StartWorkAt = configuration.GetSection("WorkingHours").GetValue <int>("Start"); EndWorkAt = configuration.GetSection("WorkingHours").GetValue <int>("End"); }
public ClientController(GymContext context, IConfiguration config) { db = context; configuration = config; ItemsOnPage = configuration.GetSection("ViewSettings").GetValue <int>("ItemsOnPage"); StartWorkAt = configuration.GetSection("WorkingHours").GetValue <int>("Start"); EndWorkAt = configuration.GetSection("WorkingHours").GetValue <int>("End"); }
public void Update(TEntity entity) { using (var context = new GymContext()) { var updatedEntity = context.Entry(entity); updatedEntity.State = EntityState.Modified; context.SaveChanges(); } }
public List <TrainingProgram> GetExercise() { using (var db = new GymContext()) { var exercises = db.TrainingProgram.Where(t => t.UserId == CurrentUser.Id).ToList(); //var exercises = db.TrainingProgram.ToList(); return(exercises); } }
public void EliminarUnPlanDeGimnasioPorCodigo() { using (var context = new GymContext()) { var eliminarplan = context.TBPLANs.Where(c => c.Codigo == "P03").FirstOrDefault(); context.TBPLANs.Remove(eliminarplan); context.SaveChanges(); } }
public void Delete(int trainingId) { using (var db = new GymContext()) { Training = db.TrainingProgram.Where(t => t.TrainingId == trainingId).FirstOrDefault(); db.Remove(Training); db.SaveChanges(); } }
public void Insert(TEntity entity) { using (var context = new GymContext()) { var addedEntity = context.Entry(entity); addedEntity.State = EntityState.Added; context.SaveChanges(); } }
public ActionResult AssignRoleToUser() { GymContext db = new GymContext(); ViewBag.Users = new SelectList(db.Users, "Id", "UserName"); ViewBag.Roles = new SelectList(db.Role, "RoleId", "RoleName"); return(View()); }
public void RegisterUser(string firstName, string lastName, string username, string email, string password) { using var db = new GymContext(); //var user = db.Users; //string encryptedPassword = Encrypt(password); db.Add(new User { FirstName = firstName, LastName = lastName, UserName = username, Email = email, Password = password }); db.SaveChanges(); }
public async Task <UserContext> RegisterGymUser(string email, string password, string userName) { GymContext userGymContext = new GymContext(email, password, userName); userGymContext.UserType = "Gym"; userGymContext.Created = DateTime.Now; var result = await SaveGym(userGymContext); return(result); }
public ActionResult Report(string id) { LocalReport lr = new LocalReport(); string path = Path.Combine(Server.MapPath("~/Clases"), "Productos.rdlc"); if (System.IO.File.Exists(path)) { lr.ReportPath = path; } else { return(View("Index")); } List <Producto> cm = new List <Producto>(); using (GymContext dc = new GymContext()) { cm = dc.Productoes.ToList(); } ReportDataSource rd = new ReportDataSource("DataSet1", cm); lr.DataSources.Add(rd); string reportType = id; string mimeType; string encoding; string fileNameExtension; string deviceInfo = "<DeviceInfo>" + " <OutputFormat>" + id + "</OutputFormat>" + " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>" + " <MarginTop>0.5in</MarginTop>" + " <MarginLeft>1in</MarginLeft>" + " <MarginRight>1in</MarginRight>" + " <MarginBottom>0.5in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; string[] streams; byte[] renderedBytes; renderedBytes = lr.Render( reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings); return(File(renderedBytes, mimeType)); }
public UserService(GymContext context, IHasher hasher, IConfiguration config) { _config = config; _context = context; _hasher = hasher; Secret1 = _config.GetConnectionString("Secret1"); EmailPort = int.Parse(_config.GetConnectionString("EmailPort")); EmailPassword = _config.GetConnectionString("EmailPassword"); SenderEmail = _config.GetConnectionString("SenderEmail"); EmailHost = _config.GetConnectionString("EmailHost"); }
public void Delete(int id) { //_context.Remove<TEntity>(Get(id)); //_context.SaveChanges(); using (var context = new GymContext()) { var deletedEntity = context.Entry(Get(id)); deletedEntity.State = EntityState.Deleted; context.SaveChanges(); } }
public void CreateTraining(int userId, string trainingType, string difficulty, string dailyPlan) { using (var db = new GymContext()) { db.Add(new TrainingProgram { UserId = userId, TrainingType = trainingType, Difficulty = difficulty, DailyPlan = dailyPlan }); db.SaveChanges(); } }
static void Main(string[] args) { using (GymContext context = new GymContext()) { var aga = new Profile(1, "Aga", "Hussein", 22, 110); context.Profiles.Add(aga); context.SaveChanges(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }