public bool ReservationExist(Term term, FitnessUser user) { return(session.CreateCriteria <Reservation>() .Add(Restrictions.Eq("User", user)) .Add(Restrictions.Eq("Term", term)) .UniqueResult <Reservation>() == null ? false : true); }
public async Task <IActionResult> ViewGoal(long ID) { FitnessUser currentUser = await GetUser(); Goal goal = await storageService.GetGoalByID(currentUser, ID); if (goal == null) { return(BadRequest()); } GoalProgress[] progress = await storageService.GetGoalProgress(currentUser, ID); if (progress == null) { return(BadRequest()); } GoalViewModel viewModel = new GoalViewModel() { Goal = goal, Progress = progress }; return(View(viewModel)); }
public IList <Term> GetNewTermsByTrainer(FitnessUser trainer) { return(session.CreateCriteria <Term>() .Add(Restrictions.Eq("Trainer", trainer)) .Add(Restrictions.Ge("EndTerm", DateTime.Now)) .List <Term>()); }
// GET: Admin/Reservation public ActionResult Index(int?page, int?item) { int itemsOnPage = item ?? 5; int pg = page ?? 1; UserDao uDao = new UserDao(); FitnessUser u = uDao.GetByLogin(User.Identity.Name); ReservationDao rDao = new ReservationDao(); IList <Reservation> res = null; if (u.Role.Name == "Zákazník") { res = rDao.GetReservationPageByUser(itemsOnPage, pg, u); } else { res = rDao.GetReservationPage(itemsOnPage, pg); } ViewBag.Pages = (int)Math.Ceiling((double)rDao.GetAll().Count / (double)itemsOnPage); ViewBag.CurrentPage = pg; ViewBag.Items = itemsOnPage; ViewBag.Mark = "Reservation"; if (Request.IsAjaxRequest()) { return(PartialView(res)); } return(View(res)); }
public override bool ValidateUser(string username, string password) { UserDao uDao = new UserDao(); FitnessUser fitnessUser = uDao.GetByLoginAndPassword(username, password); return(fitnessUser != null); }
public async Task <IActionResult> EditRecords(DateTime Date, long[] FoodIDs, float[] Quantities) { if (FoodIDs.Length != Quantities.Length || FoodIDs.Length == 0) { return(BadRequest()); } FitnessUser currentUser = await userManager.GetUserAsync(HttpContext.User); FoodRecord[] existingRecords = await dbContext.FoodRecords.Where(record => record.User == currentUser && record.ConsumptionDate == Date).ToArrayAsync(); dbContext.FoodRecords.RemoveRange(existingRecords); FoodRecord[] newRecords = new FoodRecord[FoodIDs.Length]; for (int i = 0; i < FoodIDs.Length; i++) { newRecords[i] = new FoodRecord() { ConsumptionDate = Date, User = currentUser, FoodID = FoodIDs[i], Quantity = Quantities[i] }; } dbContext.FoodRecords.AddRange(newRecords); await dbContext.SaveChangesAsync(); return(RedirectToAction("AddFood")); }
public async Task <IActionResult> EditTarget(float TargetWeight, DateTime TargetDate) { if (TargetWeight <= 0 || TargetWeight >= 200 || TargetDate <= DateTime.Today) { return(BadRequest()); } FitnessUser currentUser = await GetUser(); BodyweightTarget newTarget = await storageService.GetBodyweightTarget(currentUser); if (newTarget == null) { newTarget = new BodyweightTarget() { User = currentUser }; } newTarget.TargetWeight = TargetWeight; newTarget.TargetDate = TargetDate; await storageService.StoreBodyweightTarget(newTarget); return(RedirectToAction("Summary")); }
public async Task DeleteExistingRecords(FitnessUser User) { BodyweightRecord[] existingRecords = await dbContext.BodyweightRecords.Where(record => record.User == User).ToArrayAsync(); dbContext.BodyweightRecords.RemoveRange(existingRecords); await dbContext.SaveChangesAsync(); }
public ActionResult UpdateLog(FitnessUser fitnessUser, int roleId, int addressId) { UserDao uDao = new UserDao(); FitnessUser u = uDao.GetById(fitnessUser.Id); bool LoginExist = false; fitnessUser.Address = new AddressDao().GetById(addressId); fitnessUser.Role = new RoleDao().GetById(roleId); fitnessUser.Password = PasswordHash.CreateHash(fitnessUser.Password); if (fitnessUser.Login != u.Login) { LoginExist = uDao.LoginExist(fitnessUser.Login); } if (LoginExist == false) { uDao.Update(fitnessUser); TempData["message-success"] = "Uživatel " + fitnessUser.Name + " byl úspěšně upraven"; } else { TempData["warning"] = "Uživatel pod tímto loginem již existuje!"; return(View("EditLog", fitnessUser)); } return(RedirectToAction("Logout", "Home")); }
// GET: Admin/Machine public ActionResult Index(int?page, int?item) { int itemsOnPage = item ?? 5; int pg = page ?? 1; MachineDao mDao = new MachineDao(); IList <Machine> machs = mDao.GetMachinePage(itemsOnPage, pg); UserDao uDao = new UserDao(); FitnessUser u = uDao.GetByLogin(User.Identity.Name); ViewBag.Pages = (int)Math.Ceiling((double)mDao.GetAll().Count / (double)itemsOnPage); ViewBag.CurrentPage = pg; ViewBag.Items = itemsOnPage; ViewBag.Mark = "Machine"; if (Request.IsAjaxRequest()) { if (u.Role.Name != "Údržbář") { return(PartialView("CustomerIndex", machs)); } return(PartialView(machs)); } else { if (u.Role.Name != "Údržbář") { return(View("CustomerIndex", machs)); } return(View(machs)); } }
public ActionResult DeletePicture(int id, string view) { try { UserDao uDao = new UserDao(); FitnessUser u = uDao.GetById(id); if (u.SmallImageName != null) { System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + u.SmallImageName)); } if (u.BigImageName != null) { System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + u.BigImageName)); } u.SmallImageName = null; u.BigImageName = null; TempData["succes"] = "Obrázek stroje odstraněn."; if (view == "Emp") { return(View("EditEmployee", u)); } return(View("EditUser", u)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public ActionResult SignIn(string login, string password) { UserDao uDao = new UserDao(); FitnessUser u = uDao.GetByLogin(login); if (u != null && PasswordHash.ValidatePassword(password, u.Password)) { password = u.Password; } else { TempData["error"] = "Přihlašovací údaje nejsou správné"; return(RedirectToAction("Index")); } if (Membership.ValidateUser(login, password)) { FormsAuthentication.SetAuthCookie(login, false); TempData["success"] = "Přihlašení proběhlo správně"; return(RedirectToAction("Index", "Home", new { area = "Admin" })); } TempData["error"] = "Přihlašovací údaje nejsou správné"; return(RedirectToAction("Index")); }
public ActionResult Delete(int id) { try { UserDao uDao = new UserDao(); AddressDao aDao = new AddressDao(); FitnessUser fitnessUser = uDao.GetById(id); Address address = new Address(); address = fitnessUser.Address; //pokud se jedná o trenéra, je třeba smazat jeho termíny, které vede if (fitnessUser.Role.Name == "Trenér") { TermDao tDao = new TermDao(); IList <Term> terms = tDao.GetTermsByTrainer(fitnessUser); foreach (Term t in terms) { tDao.Delete(t); } }//pokud se jedna o zakaznika, je treba smazat rezervace, na ktere je zapsan else if (fitnessUser.Role.Name == "Zákazník") { ReservationDao rDao = new ReservationDao(); IList <Reservation> reservations = rDao.GetAllReservationsByUser(fitnessUser); foreach (Reservation r in reservations) { rDao.Delete(r); } } if (fitnessUser.SmallImageName != null) { System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + fitnessUser.SmallImageName)); } if (fitnessUser.BigImageName != null) { System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + fitnessUser.BigImageName)); } uDao.Delete(fitnessUser); aDao.Delete(address); TempData["succes"] = "Uživatelský účet byl odstraněn."; if (fitnessUser.Login == User.Identity.Name) { return(RedirectToAction("Logout", "Home")); } return(RedirectToAction("Index", "Home")); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task <IActionResult> Summary() { FitnessUser currentUser = await GetUser(); WorkoutPlan[] plans = await dbContext.WorkoutPlans.Where(plan => plan.User == currentUser).ToArrayAsync(); return(View(plans)); }
public async Task <IActionResult> EditRecords() { FitnessUser currentUser = await GetUser(); BodyweightRecord[] records = await storageService.GetBodyweightRecords(currentUser); return(View(records)); }
public async Task <IActionResult> Summary() { FitnessUser currentUser = await GetUser(); Goal[] goals = await storageService.GetAllGoals(currentUser); return(View(goals)); }
public async Task <IActionResult> EditTarget() { FitnessUser currentUser = await GetUser(); BodyweightTarget target = await storageService.GetBodyweightTarget(currentUser); return(View(target)); }
public ActionResult EditLog(int id) { UserDao uDao = new UserDao(); FitnessUser fitnessUser = uDao.GetById(id); ViewBag.Mark = "User"; return(View(fitnessUser)); }
public IList <Reservation> GetReservationPageByUser(int count, int page, FitnessUser fitnessUser) { return(session.CreateCriteria <Reservation>() .Add(Restrictions.Eq("User", fitnessUser)) .AddOrder(Order.Asc("ReservationTime")) .SetFirstResult((page - 1) * count) .SetMaxResults(count) .List <Reservation>()); }
public async Task <IActionResult> GetBodyweightData(int PreviousDays) { FitnessUser currentUser = await GetUser(); BodyweightRecord[] records = await storageService.GetBodyweightRecords(currentUser, true); var result = records.Select(record => new { Date = record.Date.ToString("d"), Weight = record.Weight }).ToArray(); return(Json(result)); }
public ActionResult AddUser(FitnessUser fitnessUser, HttpPostedFileBase picture) { try { if (ModelState.IsValid) { if (picture != null) { ImageClass.ImageMethod(picture, "FitnessUser", out string bigImageName, out string smallImageName, out string tempData); if (tempData != null) { TempData["warning"] = tempData; } fitnessUser.BigImageName = bigImageName; fitnessUser.SmallImageName = smallImageName; } UserDao uDao = new UserDao(); AddressDao aDao = new AddressDao(); Address a = new Address(); fitnessUser.Role = new RoleDao().GetById(399); fitnessUser.Password = PasswordHash.CreateHash(fitnessUser.Password); a = fitnessUser.Address; if (uDao.LoginExist(fitnessUser.Login) == false) { aDao.Create(a); fitnessUser.Address = a; uDao.Create(fitnessUser); } else { TempData["warning"] = "Uživatel pod tímto loginem již existuje!"; return(View("CreateUser", fitnessUser)); } } else { return(View("CreateUser", fitnessUser)); } if (TempData["warning"] == null) { TempData["succes"] = "Registrace proběhla úspěšně."; } } catch (Exception e) { Console.WriteLine(e); throw; } return(RedirectToAction("Index", "Home")); }
public override string[] GetRolesForUser(string username) { UserDao uDao = new UserDao(); FitnessUser fitnessUser = uDao.GetByLogin(username); if (fitnessUser == null) { return(new string[] { }); } return(new string[] { fitnessUser.Role.Name }); }
public override bool IsUserInRole(string username, string roleName) { UserDao uDao = new UserDao(); FitnessUser fitnessUser = uDao.GetByLogin(username); if (fitnessUser == null) { return(false); } return(fitnessUser.Role.Name == roleName); }
public async Task <IActionResult> Summary() { FitnessUser currentUser = await GetUser(); IEnumerable <BodyweightRecord> records = await storageService.GetBodyweightRecords(currentUser); BodyweightTarget target = await storageService.GetBodyweightTarget(currentUser); BodyweightSummaryViewModel viewModel = new BodyweightSummaryViewModel(records, target); return(View(viewModel)); }
public async Task <IActionResult> GetWeightliftingProgress(long GoalID) { FitnessUser currentUser = await GetUser(); GoalProgress[] progress = await storageService.GetGoalProgress(currentUser, GoalID, true); var result = Array.ConvertAll(progress, item => (WeightliftingProgress)item) .Select(record => new { Date = record.Date.ToString("d"), Weight = record.Weight, Reps = record.Reps }) .ToArray(); return(Json(result)); }
public async Task <IActionResult> GetTimedProgress(long GoalID) { FitnessUser currentUser = await GetUser(); GoalProgress[] progress = await storageService.GetGoalProgress(currentUser, GoalID, true); var result = Array.ConvertAll(progress, item => (TimedProgress)item) .Select(record => new { Date = record.Date.ToString("d"), Timespan = record.Time, Quantity = record.Quantity, QuantityUnit = record.QuantityUnit }) .ToArray(); return(Json(result)); }
public ActionResult UpdateUser(FitnessUser fitnessUser, HttpPostedFileBase picture, int roleId, int addressId) { try { if (ModelState.IsValid) { if (picture != null) { ImageClass.ImageMethod(picture, "FitnessUser", out string bigImageName, out string smallImageName, out string tempData); if (tempData != null) { TempData["warning"] = tempData; } if (fitnessUser.SmallImageName != null) { System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + fitnessUser.SmallImageName)); } if (fitnessUser.BigImageName != null) { System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + fitnessUser.BigImageName)); } fitnessUser.BigImageName = bigImageName; fitnessUser.SmallImageName = smallImageName; } UserDao uDao = new UserDao(); RoleDao rDao = new RoleDao(); AddressDao aDao = new AddressDao(); fitnessUser.Role = rDao.GetById(roleId); fitnessUser.Address = aDao.GetById(addressId); uDao.Update(fitnessUser); } else { return(View("EditUser", fitnessUser)); } if (TempData["warning"] == null) { TempData["succes"] = "Úprava Vašeho profilu proběhla úspěšně."; } } catch (Exception e) { Console.WriteLine(e); throw; } return(RedirectToAction("Index", "Home")); }
public async Task DeleteGoalByID(FitnessUser User, long GoalID) { Goal existingGoal = await dbContext.Goals.FirstOrDefaultAsync(goal => goal.ID == GoalID && goal.User == User); if (existingGoal == null) { return; } dbContext.Goals.Remove(existingGoal); await dbContext.SaveChangesAsync(); }
public ActionResult Detail(int id) { UserDao uDao = new UserDao(); FitnessUser user = uDao.GetById(id); ViewBag.CurrentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name; ViewBag.Mark = "User"; if (Request.IsAjaxRequest()) { return(PartialView(user)); } return(View(user)); }
public async Task <IActionResult> EditGoal(long ID) { FitnessUser currentUser = await GetUser(); Goal goal = await storageService.GetGoalByID(currentUser, ID); if (goal == null) { return(BadRequest()); } return(View(goal)); }