public async Task <IActionResult> outcome(string outcome) { double outcome2 = Convert.ToDouble(outcome); var pay = await _context.PersonalPay.OrderBy(m => m.create_time).LastOrDefaultAsync(m => m.user_id == User.Identity.Name); string last = pay.create_time.ToString("MM-dd"); string time = DateTime.Now.ToString("MM-dd"); if (time.Equals(last)) { pay.pay = outcome2; _context.Update(pay); _context.SaveChanges(); } else { var pay2 = new PersonalPay(); pay2.create_time = DateTime.Now; pay2.user_id = User.Identity.Name; pay.pay = outcome2; _context.Add(pay2); _context.SaveChanges(); ; } result res = new result(); res.ok = "ok"; var ans = Json(res); return(ans); }
public async Task <IActionResult> Create([Bind("ID,user_id,create_time,Trun_time,Trun_score,Gunrun_time,Gunrun_score,score,age")] SpeedAbility speedAbility, string type) { speedAbility.create_time = DateTime.Now; speedAbility.Trun_score = (int)speedAbility.Trun_time * 20 - 160; var s = await _context.Gunrun_Score.SingleOrDefaultAsync(m => m.age == speedAbility.age && m.num == speedAbility.Gunrun_time); speedAbility.Gunrun_score = s.score * 20 + 40; speedAbility.score = (speedAbility.Trun_score + speedAbility.Gunrun_score) / 2; if (type == "yes") { _context.Add(speedAbility); await _context.SaveChangesAsync(); } Result res = new Result(); res.Trunnum = speedAbility.Trun_score.ToString(); res.Gunrunnum = speedAbility.Gunrun_score.ToString(); JsonResult result = Json(res); return(result); }
public async Task <IActionResult> Create([Bind("ID,user_id,create_time,age,fourrun_time,fourrun_score,threerun_time,threerun_score,score")] StaminaAbility staminaAbility, string type) { staminaAbility.create_time = DateTime.Now; var s = await _context.Fourrun_Score.SingleOrDefaultAsync(m => m.age == staminaAbility.age && m.num == staminaAbility.fourrun_time); staminaAbility.fourrun_score = s.score * 20 + 40; staminaAbility.threerun_score = (int)(staminaAbility.threerun_time * 2 + 55.4); staminaAbility.score = (staminaAbility.fourrun_score + staminaAbility.threerun_score) / 2; if (type == "yes") { _context.Add(staminaAbility); await _context.SaveChangesAsync(); } Result res = new Result(); res.Fournum = staminaAbility.fourrun_score.ToString(); res.Threenum = staminaAbility.threerun_score.ToString(); JsonResult result = Json(res); return(result); }
public IActionResult GetAnswer(string id, string answer, string correctAnswer) { var list = _context.UsersAnswers; var users = _context.Users.Where(u => u.Email == User.Identity.Name); string userId = ""; foreach (var el in users) { userId = el.Id; } var answers = list.Where(p => p.QuestionId == Convert.ToInt32(id) && p.UserId == userId); var question = _context.Questions.Find(Convert.ToInt32(id)); bool result = answer == correctAnswer; int TestId = question.TestId; if (answers.Count() != 0) { var el = answers.First(); el.IsCorrectAnswer = result; _context.Update(el); _context.SaveChanges(); } else { MyWebTest.Models.UsersAnswer ans = new UsersAnswer() { IsCorrectAnswer = result, UserId = userId, QuestionId = Convert.ToInt32(id) }; _context.Add(ans); _context.SaveChanges(); } return(RedirectToRoute("start_test", new { id = TestId.ToString() })); }
public async Task <IActionResult> Create([Bind("ID,user_id,back_train,chesk_train,Leg_train,shoulder_train,arm_train,abdomen_train,stamina_train,explosive_train")] PersonalNormlTrain personalNormlTrain) { if (ModelState.IsValid) { _context.Add(personalNormlTrain); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(personalNormlTrain)); }
public async Task <IActionResult> Create([Bind("ID,name,password")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Create([Bind("Id_Produto,Nome,Valor,Data_Cadastro,ID_Fornecedor")] ProdutoModel produtoModel) { if (ModelState.IsValid) { _context.Add(produtoModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ID_Fornecedor"] = new SelectList(_context.Fornecedores, "ID_Fornecedor", "ID_Fornecedor", produtoModel.ID_Fornecedor); return(View(produtoModel)); }
public async Task <IActionResult> Create([Bind("ID_Fornecedor,Nome,CNPJ,Ativo,Data_Cadastro")] FornecedorModel fornecedorModel) { if (ModelState.IsValid) { VerificarData(fornecedorModel); _context.Add(fornecedorModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(fornecedorModel)); }
public async Task <IActionResult> Create([Bind("user_id,height,weight,age,waist,")] BodyAbility bodyAbility) { bodyAbility.create_time = DateTime.Now; //计算体脂率的公式 bodyAbility.bfp = (double)(bodyAbility.waist * 0.74 - (bodyAbility.weight * 0.082 + 44.74)) / bodyAbility.weight; bodyAbility.bfp = bodyAbility.bfp * 100; //计算BMI的公式 bodyAbility.bmi = (double)bodyAbility.weight / (bodyAbility.height * bodyAbility.height); _context.Add(bodyAbility); await _context.SaveChangesAsync(); result res = new result(); //系统建议的代码,仿照这个代码,在别的类中,同样的位置,试着自己编写 res.ans = ""; if (res.bfp < 15) { res.ans += "您的体脂率比较低,建议多摄入脂肪;"; } else if (res.bfp >= 15 && res.bfp <= 18) { res.ans += "您的体脂率正常"; } else { res.ans += "您的体脂率过高,注意多锻炼"; } if (res.bmi < 18.5) { res.ans += "您的BMI指数偏低,需要多锻炼身体"; } else if (res.bmi >= 18.5 && res.bmi < 23.9) { res.ans += "您的BMI指数正常"; } else { res.ans += "您的BMI指数偏高,需要多锻炼"; } res.bfp = bodyAbility.bfp; res.bmi = bodyAbility.bmi; JsonResult result = Json(res); return(result); }
public async Task <IActionResult> Create([Bind("ID,user_id,create_time,flexible_num")] FlexibleAbility flexibleAbility) { flexibleAbility.flexible_score = flexibleAbility.flexible_num * 4 + 60; flexibleAbility.create_time = DateTime.Now; _context.Add(flexibleAbility); await _context.SaveChangesAsync(); Result res = new Result(); res.num = flexibleAbility.flexible_score.ToString(); JsonResult result = Json(res); return(result); }
public async Task <IActionResult> Create([Bind("ID,user_id,create_time,age,fourhurdle_time")] FourhurdleAbilities fourhurdleAbilities, string type) { fourhurdleAbilities.create_time = DateTime.Now; var s = await _context.Fourhurdle_Score.SingleOrDefaultAsync(m => m.age == fourhurdleAbilities.age && m.num == fourhurdleAbilities.fourhurdle_time); fourhurdleAbilities.fourhurdle_score = s.score * 20 + 40; if (type == "yes") { _context.Add(fourhurdleAbilities); await _context.SaveChangesAsync(); } Result res = new Result(); res.num = fourhurdleAbilities.fourhurdle_score.ToString(); JsonResult result = Json(res); return(result); }
public async Task <IActionResult> Create([Bind("ID,user_id,create_time,age,gunhurdle_time,gunhurdle_score,threeoffroad_time,threeoffroad_score,twohurdle_time,twohurdle_score,threehurdle_time,threehurdle_score,score")] ComtrainAbilities comtrainAbilities, string type) { comtrainAbilities.create_time = DateTime.Now; var s = await _context.Gunhurdle_Score.SingleOrDefaultAsync(m => m.age == comtrainAbilities.age && m.num == comtrainAbilities.gunhurdle_time); comtrainAbilities.gunhurdle_score = s.score * 20 + 40; var s2 = await _context.Threeoffroad_Score.SingleOrDefaultAsync(m => m.age == comtrainAbilities.age && m.num == comtrainAbilities.threeoffroad_time); comtrainAbilities.threeoffroad_score = s2.score * 20 + 40; var s3 = await _context.Threehurdle_Score.SingleOrDefaultAsync(m => m.age == comtrainAbilities.age && m.num == comtrainAbilities.threehurdle_time); comtrainAbilities.threehurdle_score = s3.score * 20 + 40; var s4 = await _context.Twohurdle_Score.SingleOrDefaultAsync(m => m.age == comtrainAbilities.age && m.num == comtrainAbilities.twohurdle_time); comtrainAbilities.twohurdle_score = s4.score * 20 + 40; comtrainAbilities.score = (comtrainAbilities.gunhurdle_score + comtrainAbilities.threehurdle_score + comtrainAbilities.threehurdle_score + comtrainAbilities.twohurdle_score) / 4; if (type == "yes") { _context.Add(comtrainAbilities); await _context.SaveChangesAsync(); } Result res = new Result(); res.gunhurdlescore = comtrainAbilities.gunhurdle_score.ToString(); res.threehurdlescore = comtrainAbilities.threehurdle_score.ToString(); res.twohurdlescore = comtrainAbilities.twohurdle_score.ToString(); res.threeoffroadscore = comtrainAbilities.threeoffroad_score.ToString(); JsonResult result = Json(res); return(result); }
public async Task <IActionResult> check(int back_train, int chesk_train, int leg_train, int shoulder_train, int stamina_train, int explosive_train, int arm_train, int abdomen_train) { var normaltrain = await _context.NormalTrain.LastOrDefaultAsync(m => m.user_id == User.Identity.Name); if (normaltrain == null) { normaltrain = new NormalTrain(); normaltrain.abdomen_train = 0; normaltrain.arm_train = 0; normaltrain.back_train = 0; normaltrain.chesk_train = 0; normaltrain.explosive_train = 0; normaltrain.Leg_train = 0; normaltrain.shoulder_train = 0; normaltrain.stamina_train = 0; normaltrain.user_id = User.Identity.Name; normaltrain.create_time = DateTime.Now; _context.Add(normaltrain); _context.SaveChanges(); } else { if (back_train == 0) { normaltrain.back_train = 0; } else { normaltrain.back_train++; } if (chesk_train == 0) { normaltrain.chesk_train = 0; } else { normaltrain.chesk_train++; } if (leg_train == 0) { normaltrain.Leg_train = 0; } else { normaltrain.Leg_train++; } if (shoulder_train == 0) { normaltrain.shoulder_train = 0; } else { normaltrain.shoulder_train++; } if (stamina_train == 0) { normaltrain.stamina_train = 0; } else { normaltrain.stamina_train++; } if (explosive_train == 0) { normaltrain.explosive_train = 0; } else { normaltrain.explosive_train++; } if (arm_train == 0) { normaltrain.arm_train = 0; } else { normaltrain.arm_train++; } if (abdomen_train == 0) { normaltrain.abdomen_train = 0; } else { normaltrain.abdomen_train++; } normaltrain.create_time = DateTime.Now; _context.Update(normaltrain); await _context.SaveChangesAsync(); } result res = new result(); res.back_train = normaltrain.back_train; res.chesk_train = normaltrain.chesk_train; res.explosive_train = normaltrain.explosive_train; res.abdomen_train = normaltrain.abdomen_train; res.arm_train = normaltrain.arm_train; res.leg_train = normaltrain.Leg_train; res.shoulder_train = normaltrain.shoulder_train; res.stamina_train = normaltrain.stamina_train; JsonResult result = Json(res); return(result); }
public async Task <IActionResult> Create([Bind("ID,user_id,horbara_num,horbarb_num,doubara_num,doubarb_num,pushup_num,situp_num,age")] EnergyAbility energyAbility, string type) { energyAbility.create_time = DateTime.Now; var s = await _context.Horbara_Score.SingleOrDefaultAsync(m => m.age == energyAbility.age && m.num == energyAbility.horbara_num); energyAbility.horbara_score = s.score; var s2 = await _context.Ontheroll_Score.SingleOrDefaultAsync(m => m.age == energyAbility.age && m.num == energyAbility.horbarb_num); if (s2.score == 1) { s2.score = 60; } else if (s2.score == 2) { s2.score = 80; } else { s2.score = 100; } energyAbility.horbarb_score = s2.score; if (energyAbility.doubara_num <= 8) { energyAbility.doubara_score = 60; } else if (energyAbility.doubara_num > 8 && energyAbility.doubara_num <= 12) { energyAbility.doubara_score = 80; } else { energyAbility.doubara_score = 100; } var s3 = await _context.Swingflex_Score.SingleOrDefaultAsync(m => m.age == energyAbility.age && m.num == energyAbility.doubarb_num); if (s3.score == 1) { s3.score = 60; } else if (s3.score == 2) { s3.score = 80; } else { s3.score = 100; } energyAbility.doubarb_score = s3.score; var s4 = await _context.Pushup_Score.SingleOrDefaultAsync(m => m.age == energyAbility.age && m.num == energyAbility.pushup_num); energyAbility.pushup_score = s4.score; var s5 = await _context.Situp_Score.SingleOrDefaultAsync(m => m.age == energyAbility.age && m.num == energyAbility.situp_num); energyAbility.situp_score = s5.score; energyAbility.score = (int)(energyAbility.horbara_score + energyAbility.horbarb_score + energyAbility.doubara_score + energyAbility.doubarb_score + energyAbility.doubarb_score + energyAbility.pushup_score + energyAbility.situp_score) / 7; if (type == "yes") { _context.Add(energyAbility); await _context.SaveChangesAsync(); } Result result = new Result(); result.horbara = energyAbility.horbara_score; result.horbarb = energyAbility.horbarb_score; result.doubara = energyAbility.doubara_score; result.doubarb = energyAbility.doubarb_score; result.pushup = energyAbility.pushup_score; result.situp = energyAbility.situp_score; JsonResult res = Json(result); return(res); }
public async Task <IActionResult> CreateB(CreateBookViewModel model, IFormFile file) { if (ModelState.IsValid) { string[] _genre = (from t in JsonConvert.DeserializeObject <Dictionary <string, string>[]>(model.Genre) select t["value"]).ToArray(); string[] _specialty = (from s in JsonConvert.DeserializeObject <Dictionary <string, string>[]>(model.Specialty) select s["value"]).ToArray(); string[] _discipline = (from d in JsonConvert.DeserializeObject <Dictionary <string, string>[]>(model.Discipline) select d["value"]).ToArray(); List <Genre> genres = _systemContext.Genres.Where(g => _genre.Contains(g.GenreName)).ToList(); List <Specialty> specialties = _systemContext.Specialties.Where(s => _specialty.Contains(s.NameSpecialty)).ToList(); List <Discipline> disciplines = _systemContext.Disciplines.Where(d => _discipline.Contains(d.NameDiscipline)).ToList(); Book book = new Book { Name = model.BookName, Author = model.Author, Articl = model.Articl, Description = model.Description, Year = model.Year, Count = model.Count, }; List <Chapter> chapters = new List <Chapter>(); for (int i = 0; i < model.Chapters.Count; i++) { chapters.Add(new Chapter() { Book = book, Name = model.Chapters[i], NumberChapter = i + 1 }); } book.Chapters = chapters; string path = ""; if (!string.IsNullOrEmpty(book.BookPicture)) { System.IO.File.Delete(_appEnvironment.WebRootPath + book.BookPicture); } if (file != null) { path = @"/files/book/" + book.Name + DateTime.Now.ToString("ddMMyyyyHHmmss") + Path.GetExtension(file.FileName); using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.OpenOrCreate)) { await file.CopyToAsync(fileStream); } } book.BookPicture = path; _systemContext.Add(book); foreach (Genre genre in genres) { _systemContext.BookGenres.Add(new BookGenre() { Book = book, Genre = genre }); } foreach (Discipline disc in disciplines) { _systemContext.BookDiscs.Add(new BookDisc() { Book = book, Discipline = disc }); } foreach (Specialty spec in specialties) { _systemContext.BookSpecs.Add(new BookSpec() { Book = book, Specialty = spec }); } _systemContext.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Register([FromServices] IEncryptionService _encryptionService, [FromServices] SystemContext agileLabsDbContext, [Bind] RegisterViewModel model) { if (ModelState.IsValid) { var account = new Account() { Email = model.Email, NormalizedEmail = model.Email.ToUpper(), AccountType = AccountType.Tenant }; account.PasswordFormat = model.PasswordFormat; switch (model.PasswordFormat) { case PasswordFormat.Clear: { account.Password = model.Password; } break; case PasswordFormat.Encrypted: { account.Password = _encryptionService.EncryptText(model.Password); } break; case PasswordFormat.Hashed: { string saltKey = _encryptionService.CreateSaltKey(5); account.PasswordSalt = saltKey; account.Password = _encryptionService.CreatePasswordHash(model.Password, saltKey, HashedPasswordFormat); } break; default: break; } #region Tenant Handle var tenant = new Tenant() { Name = $"Tenant-{account.Email.Substring(0, account.Email.IndexOf("@"))}" }; account.TenantId = tenant.Sysid; #endregion using (var trans = agileLabsDbContext.Database.BeginTransaction()) { var emailCheckResult = agileLabsDbContext.Accounts.FirstOrDefault(x => x.NormalizedEmail == account.NormalizedEmail) == null; if (emailCheckResult) { agileLabsDbContext.Add(tenant); agileLabsDbContext.Add(account); await agileLabsDbContext.SaveChangesAsync(); trans.Commit(); return(RedirectToAction(nameof(Login))); } else { ModelState.AddModelError(nameof(RegisterViewModel.Email), "Duplicated Email"); } } } return(View(model)); }
public void Add <T>(T entity) where T : class { _context.Add(entity); //recibe cualquier entidad _context.SaveChanges(); //guarda el objeto en db }