private async Task <BulkUploadSitesResponseDto> ProcessSite(ModelDbContext dbContext, Guid accountId, QualifiedSiteDto siteDto) { var existingSite = await dbContext.RetrieveSiteByCode(siteDto.SiteCode); var siteExists = existingSite != null; var siteId = existingSite?.Id ?? Guid.NewGuid(); string siteState; if (siteExists) { await SoftUpdateSiteFields(dbContext, existingSite, siteDto); await dbContext.Update(existingSite); siteState = BulkUploadResponseStates.Updated; } else { var mappedSite = Mapper.Map <Site>(siteDto); mappedSite.Id = siteId; await dbContext.Add(mappedSite); var tenancyPeriod = new TenancyPeriod { Id = Guid.NewGuid(), AccountId = accountId, SiteId = siteId, Site = mappedSite, EffectiveFrom = DateTime.MinValue, EffectiveTo = DateTime.MaxValue }; await dbContext.Add(tenancyPeriod); siteState = BulkUploadResponseStates.Created; } return(new BulkUploadSitesResponseDto { Id = siteId, SiteCode = siteDto.SiteCode, State = siteState }); }
public async Task <IActionResult> Shipping(Customer model) { if (!ModelState.IsValid) { return(View(model)); } if (model.CustomerId == 0) { _contextModel.Add(model); await _contextModel.SaveChangesAsync(); } else { _contextModel.Update(model); await _contextModel.SaveChangesAsync(); } Customer customer = _contextModel.Customers.SingleOrDefault <Customer>(m => m.UserId == model.UserId); if (customer == null) { throw new ApplicationException($"Unable to load customer."); } _logger.LogInformation("Shipping information changed successfully."); StatusMessage = "Your shipping has been changed."; ViewBag.StatusMessage = StatusMessage; return(View(customer)); }
public async Task <IActionResult> Create([Bind("CustomerId,FirstName,LastName,Address,City,State,Country,UserId")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("CategoryId,Description")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("OrderId,OrderDate,ShippingAddress,City,State,Country,OrderStatus")] Order order) { if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(order)); }
public async Task <IActionResult> Create([Bind("ProductId,Name,Discription,Price,CategoryId,Active")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <CreatedResult> Post([FromBody] MpanDto mpanDto) { var mpan = Mapper.Map <Mpan>(mpanDto); var mpanId = Guid.NewGuid(); mpan.Id = mpanId; await _dbContext.Add(mpan); return(Created(new Uri($"/api/Mpan/{mpanId}", UriKind.Relative), new { id = mpanId })); }
public async Task <CreatedResult> Post([FromBody] SiteDto siteDto) { var site = Mapper.Map <Site>(siteDto); var siteId = Guid.NewGuid(); site.Id = siteId; await _dbContext.Add(site); return(Created(new Uri($"/api/Site/{siteId}", UriKind.Relative), new { id = siteId })); }
public async Task <CreatedResult> Post([FromBody] TenancyPeriodDto tenancyPeriodDto) { var tenancyPeriod = Mapper.Map <TenancyPeriod>(tenancyPeriodDto); var tenancyId = Guid.NewGuid(); tenancyPeriod.Id = tenancyId; await _dbContext.Add(tenancyPeriod); return(Created(new Uri($"/api/TenancyPeriod/{tenancyId}", UriKind.Relative), new { id = tenancyId })); }
public async Task <CreatedResult> Post([FromBody] AccountContactDto contactDto) { var contact = Mapper.Map <AccountContact>(contactDto); var contactId = Guid.NewGuid(); contact.Id = contactId; await _dbContext.Add(contact); await _reportingService.ReportAccountChanged(contactDto.AccountId.ToString()); return(Created(new Uri($"/api/Contact/{contactId}", UriKind.Relative), new { id = contactId })); }
private async Task <List <MeterBulkUploadResponseDto> > ProcessRequestMprns(ModelDbContext dbContext, Site associatedSite, MprnDto[] mprns) { var mprnResults = new List <MeterBulkUploadResponseDto>(); { foreach (var mprnDto in mprns) { var existing = await dbContext.RetrieveMprnByCore(mprnDto.MprnCore); var mprnId = existing?.Id ?? Guid.NewGuid(); string mprnState; if (existing != null) { await SoftUpdateMprnFields(dbContext, associatedSite, existing, mprnDto); await dbContext.Update(existing); mprnState = BulkUploadResponseStates.Updated; } else { var mprn = Mapper.Map <Mprn>(mprnDto); mprn.Id = mprnId; mprn.Site = associatedSite; await dbContext.Add(mprn); mprnState = BulkUploadResponseStates.Created; } mprnResults.Add(new MeterBulkUploadResponseDto { Core = mprnDto.MprnCore, Id = mprnId, State = mprnState }); } return(mprnResults); } }
public IActionResult Index() { List <RuntimeModelMeta.ModelPropertyMeta> modelmeta = new List <RuntimeModelMeta.ModelPropertyMeta>(); modelmeta.Add(new RuntimeModelMeta.ModelPropertyMeta() { Id = 1, PropertyName = "Size", Name = "尺寸", ValueType = "string", Length = 20 }); modelmeta.Add(new RuntimeModelMeta.ModelPropertyMeta() { Id = 2, PropertyName = "Name", Name = "名称", ValueType = "string", Length = 20 }); modelmeta.Add(new RuntimeModelMeta.ModelPropertyMeta() { Id = 3, PropertyName = "Color", Name = "颜色", ValueType = "string", Length = 20 }); modelmeta.Add(new RuntimeModelMeta.ModelPropertyMeta() { Id = 4, PropertyName = "Version", Name = "版本", ValueType = "timestamp" }); var s = JsonConvert.SerializeObject(modelmeta); RuntimeModelMeta meta = new RuntimeModelMeta(); meta.ClassName = "BareDiamond"; meta.ModelName = "BareDiamond"; meta.Properties = s; _modeldbContext.Add(meta); _modeldbContext.SaveChanges(); foreach (var item in _modeldbContext.Metas) { _dbContext.CreateModel(item); } Type modelType = _privader.GetType(1); //获取id=1的模型类型 object obj = Activator.CreateInstance(modelType); //创建实体 var entity = obj as DynamicEntity; //类型转换,目的是进行赋值 entity["Id"] = 1; entity["Name"] = "名称"; entity["Size"] = "10*20"; entity["Color"] = "red"; _dbContext.Add(entity); _dbContext.SaveChanges(); return(View()); }
public ActionResult PreTest(TestModel myModel, IFormCollection form, string id) { CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddMinutes(1200); option.IsEssential = true; Response.Cookies.Append("CaseId", id, option); Response.Cookies.Append("lastVisited", "PreTest", option); var check = User.Identity.IsAuthenticated; if (!check) { return(RedirectToAction("Account", "Identity", new { id = "Login" })); } TestModel myTestModel = myModel; int userID = int.Parse(Request.Cookies["uID"]); int caseID = int.Parse(id); if (id != null) { caseID = int.Parse(id); } using (var db = new ModelDbContext()) { int checkTaken = (from c in db.DataCollectionTable where c.Case_Id == caseID && c.User_Id == userID && c.Pre_Test == 1 select c.Answer_Id).Count(); if (checkTaken == 0) { int?myAttempt = (from a in db.AttemptTable where a.Case_Id == caseID && a.User_Id == userID && a.Pre_Test == 0 select a.Attempt_Id).Count(); Attempt_Table newAttempt = new Attempt_Table() { Attempt = 1, User_Id = userID, Case_Id = caseID, Date_Time = DateTime.Now, Pre_Test = 1 }; db.Add(newAttempt); db.SaveChanges(); foreach (var answerID in myTestModel.SelectedPreTestAnswer) { int questionID = myTestModel.getQuestionID(answerID); Data_Collection_Table collectAnswer = new Data_Collection_Table { User_Id = userID, Answer_Id = answerID, Pre_Test = 1, Attempt = null, Question_Id = questionID, Case_Id = caseID }; db.Add(collectAnswer); } db.SaveChanges(); } return(RedirectToAction("Activity", "CME", new { id = caseID, q = 0 })); } }
public ActionResult Evaluation(TestModel myModel, string id) { CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddMinutes(1200); option.IsEssential = true; Response.Cookies.Append("CaseId", id, option); Response.Cookies.Append("lastVisited", "Evaluation", option); var check = User.Identity.IsAuthenticated; if (!check) { return(RedirectToAction("Account", "Identity", new { id = "Login" })); } TestModel myTestModel = myModel; int userID = int.Parse(Request.Cookies["uID"].ToString()); int caseID = 422; if (id != null) { caseID = int.Parse(id); } if (myTestModel.IsEvalAlreadyTaken(userID, caseID) != false) { return(RedirectToAction("ClaimCredit", "CME", new { id = caseID })); } bool IsEarned = myTestModel.IsEarned(userID, caseID); if (IsEarned != true) { return(RedirectToAction("PostTest", "CME", new { id = caseID })); } //6)Confident //7)strongly agree //8)If Yes //10/Excellent //14/Text Only //22)Always Often int countEvalQuestions = myTestModel.getEvalQuestions(caseID).Count(); int ifYesTextBoxAdder = 0; int textBoxOnlyAdder = 0; int selectedEvaluationAdder = 0; for (int i = 0; i < countEvalQuestions; i++) { List <int> questionIDs = myTestModel.getEvalQuestions(caseID).Select(x => x.Question_Id).ToList(); int questionID = questionIDs[i]; int questionType = myTestModel.getQuestionType(questionID); if (questionType == 6 || questionType == 7 || questionType == 10 || questionType == 22) { Eval_Collector collectAnswer = new Eval_Collector { QuestionNum = (i + 1).ToString(), EvalResponseNum = myTestModel.SelectedEvaluationAnswers[selectedEvaluationAdder], EvalResponeText = null, UserId = userID, QuestionType = questionType, EvalType = 1, QuestionNumFK = questionID, EvalId = caseID, UpdateTime = DateTime.Now }; using (var db = new ModelDbContext()) { db.Add(collectAnswer); db.SaveChanges(); } selectedEvaluationAdder++; } else if (questionType == 8)//If Yes { Eval_Collector collectAnswer = new Eval_Collector { QuestionNum = (i + 1).ToString(), EvalResponseNum = myTestModel.SelectedIfYesAnswers[ifYesTextBoxAdder], EvalResponeText = myTestModel.ifYesText[ifYesTextBoxAdder], UserId = userID, QuestionType = questionType, EvalType = 1, QuestionNumFK = questionID, EvalId = caseID, UpdateTime = DateTime.Now }; using (var db = new ModelDbContext()) { db.Add(collectAnswer); db.SaveChanges(); } ifYesTextBoxAdder++; } else if (questionType == 14)//Text Only { Eval_Collector collectAnswer = new Eval_Collector { QuestionNum = (i + 1).ToString(), EvalResponseNum = null, EvalResponeText = myTestModel.textOnly[textBoxOnlyAdder], UserId = userID, QuestionType = questionType, EvalType = 1, QuestionNumFK = questionID, EvalId = caseID, UpdateTime = DateTime.Now }; using (var db = new ModelDbContext()) { db.Add(collectAnswer); db.SaveChanges(); } textBoxOnlyAdder++; } } foreach (var answerID in myTestModel.SelectedEvaluationAnswers) { int questionID = myTestModel.getQuestionID(answerID); } //db.SubmitChanges(); return(RedirectToAction("ClaimCredit", "CME", new { id = id })); //return View(myModel); }
public ActionResult Results(string id) { CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddMinutes(1200); option.IsEssential = true; Response.Cookies.Append("CaseId", id, option); Response.Cookies.Append("lastVisited", "Result", option); var check = User.Identity.IsAuthenticated; if (!check) { return(RedirectToAction("Account", "Identity", new { id = "Login" })); } int userID = int.Parse(Request.Cookies["uID"]); int caseID = 0; if (id != null) { caseID = int.Parse(id); } TestModel myTestModel = new TestModel(); myTestModel.UserId = userID.ToString(); float rounded = myTestModel.getGrade(userID, caseID); using (var db = new ModelDbContext()) { if (myTestModel.IsEarned(userID, caseID) == true) { return(RedirectToAction("Evaluation", "CME", new { id = caseID.ToString() })); } else { int?myAttempt = (from a in db.AttemptTable where a.Case_Id == caseID && a.User_Id == userID && a.Pre_Test == 0 select a.Attempt_Id).Count(); Attempt_Table newAttempt = new Attempt_Table() { Attempt = myAttempt + 1, User_Id = userID, Case_Id = caseID, Date_Time = DateTime.Now, Pre_Test = 0 }; db.Add(newAttempt); db.SaveChanges(); } if (rounded >= 75) { Earned_CE_Table earnedRecord = new Earned_CE_Table() { Case_Id = caseID, User_Id = userID, Date = DateTime.Now.ToShortDateString(), Pass = 1 }; db.Add(earnedRecord); db.SaveChanges(); } } return(View(myTestModel)); }
public ActionResult PostTest(TestModel myModel, string id) { CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddMinutes(1200); option.IsEssential = true; Response.Cookies.Append("CaseId", id, option); Response.Cookies.Append("lastVisited", "PostTest", option); var check = User.Identity.IsAuthenticated; if (!check) { return(RedirectToAction("Account", "Identity", new { id = "Login" })); } TestModel myTestModel = myModel; int userID = int.Parse(Request.Cookies["uID"]); int caseID = 0; if (id != null) { caseID = int.Parse(id); } int?attempt = myTestModel.getAttemptCount(userID, caseID); if (attempt != null) { if (attempt >= 3) { return(RedirectToAction("Results", "CME", new { id = caseID })); } else { attempt = (attempt + 1); } } else { attempt = 1; } bool IsEarned = myTestModel.IsEarned(userID, caseID); if (IsEarned == true) { return(RedirectToAction("Results", "CME", new { id = caseID })); } using (var db = new ModelDbContext()) { foreach (var answerID in myTestModel.SelectedPostTestAnswer) { int questionID = myTestModel.getQuestionID(answerID); Data_Collection_Table collectAnswer = new Data_Collection_Table { User_Id = userID, Answer_Id = answerID, Pre_Test = 0, Attempt = attempt, Question_Id = questionID, Case_Id = caseID }; db.Add(collectAnswer); } db.SaveChanges(); } return(RedirectToAction("Results", "CME", new { id = caseID })); }