public async Task <IActionResult> Create([Bind("Name, Phone, Place")] Tracker tracker) { //https://localhost:44394/Trackers/Create?Place=Vision_College Models.Business data = _context.Business.FirstOrDefault(m => m.BusinessName == tracker.Place); Guid aSPNetUsersIdfk = data.ASPNetUsersIdfk; tracker.ASPNetUsersIdfk = aSPNetUsersIdfk.ToString(); tracker.Id = Guid.NewGuid(); tracker.DateIn = DateTime.Now; tracker.DateOut = DateTime.Now.AddHours(2); //incase they forget to log out SaveCookies(tracker); _context.Add(tracker); await _context.SaveChangesAsync(); //pass through the model. https://docs.microsoft.com/en-us/aspnet/core/mvc/views/overview?view=aspnetcore-3.1 // return View(nameof(LogoutTracker)); // return View(tracker); //https://exceptionnotfound.net/asp-net-core-demystified-action-results/ // return NoContent(); return(RedirectToAction("Index")); //works // return RedirectToAction("LogoutTracker"); }
private void AddBusiness_Click(object sender, RoutedEventArgs e) { try { string emptyRichTxtBox = new TextRange(BusinessTextWork.Document.ContentStart, BusinessTextWork.Document.ContentEnd).Text; if (emptyRichTxtBox.Length - 2 == 0) { MessageBox.Show("Текстовое поле пусто!"); return; } Models.Business business = new Models.Business(); business.State = StateBox.Text; business.Date = BusinessDatePicker.SelectedDate.ToString().Remove(10, 8); business.Person = BusinessPerson.Text; business.TextWork = new TextRange(BusinessTextWork.Document.ContentStart, BusinessTextWork.Document.ContentEnd).Text; business.User = Classes.SelectUser.SelectUserID; context.Business.Add(business); context.SaveChanges(); FillTable(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,BusinessName,AdminName,BusinessAddress,Phone")] Models.Business business) { if (id != business.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(business); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BusinessExists(business.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(business)); }
private void BusinessRecord(object sender, MouseButtonEventArgs e) { try { DataGrid dg = sender as DataGrid; Models.Business row = (Models.Business)dg.SelectedItems[0]; ind = Convert.ToInt32(row.ID_Business.ToString()); using (Models.OrganizerDB context = new Models.OrganizerDB()) { var busin = context.Business.FirstOrDefault(s => s.ID_Business == ind && s.User == Classes.SelectUser.SelectUserID); if (busin != null) { StateBox.Text = busin.State; BusinessDatePicker.SelectedDate = DateTime.Parse(busin.Date); BusinessPerson.Text = busin.Person; FlowDocument flow = new FlowDocument(new Paragraph(new Run(busin.TextWork))); BusinessTextWork.Document = flow; DeleteBusiness.IsEnabled = true; ChangeBusiness.IsEnabled = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public async Task <IActionResult> QRCode(Guid?id) { //https://www.c-sharpcorner.com/article/generate-qr-code-in-net-core-using-bitmap/ QRCodeCreation QR = new QRCodeCreation(); //todo pass in the url of the business Models.Business business = _context.Business.FirstOrDefault(m => m.Id == id); //grab the business, replace any spaces string place = business.BusinessName.Replace(" ", "_"); //todo replace localhost with actual url //https://stackoverflow.com/questions/38437005/how-to-get-current-url-in-view-in-asp-net-core-1-0 //https://weblog.west-wind.com/posts/2020/Mar/13/Back-to-Basics-Rewriting-a-URL-in-ASPNET-Core {Request.Path} var location = new Uri($"{Request.Scheme}://{Request.Host}/Trackers/Create"); var url = location.AbsoluteUri; //https://localhost:44394/Trackers/Create?Place=Vision_College string path = QueryStringExtensions.AddToQueryString(url, "Place", place); ViewData["CodePlace"] = path; Bitmap qrCodeImage = QR.QRGenerate(path); return(View(BitmapToBytesCode(qrCodeImage))); }
public ActionResult DeleteConfirmed(int id) { Models.Business business = db.Business.Find(id); db.Business.Remove(business); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Id,BusinessName,AdminName,BusinessAddress,Phone")] Models.Business business) { //todo add in the guid of the current logged in person to the class if (ModelState.IsValid) { // https://stackoverflow.com/questions/30701006/how-to-get-the-current-logged-in-user-id-in-asp-net-core //todo Fix usermanager // ApplicationUser applicationUser = await _userManager.GetUserAsync(User); // string userEmail = applicationUser?.Email; // will give the user's Email //todo Fix usermanager // Guid userId = Guid.Parse(applicationUser?.Id); // will give the user's Email //var userId = _userManager.FindFirstValue(ClaimTypes.NameIdentifier); // will give the user's userId // var userName = _userManager.FindFirstValue(ClaimTypes.Name); // will give the user's userName business.BusinessName = business.BusinessName.Replace(" ", "_"); //clear out spaces business.Id = Guid.NewGuid(); // business.ASPNetUsersIdfk = userId;//todo Fix usermanager _context.Add(business); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(business)); }
public ActionResult Edit([Bind(Include = "ID,CODE,NAME,TYPE,ISAUTO,STARTDATE,ENDDATE,VALUE,FREQUENCY")] Models.Business business) { if (ModelState.IsValid) { db.Entry(business).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(business)); }
public ActionResult Create([Bind(Include = "ID,CODE,NAME,TYPE,ISAUTO,STARTDATE,ENDDATE,VALUE,FREQUENCY")] Models.Business business) { if (ModelState.IsValid) { db.Business.Add(business); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(business)); }
// GET: Businesses/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Business business = db.Business.Find(id); db.Business.Remove(business); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Create(BusinessCreateRequest model) { using var db = new salesSystemContext(); var business = new Models.Business { Address = model.Address, BusinessName = model.BusinessName, FkUserId = model.FkUserId }; db.Businesses.Add(business); db.SaveChanges(); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Business = await _context.Business.FirstOrDefaultAsync(m => m.Id == id); if (Business == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Business = await _context.Business.FindAsync(id); if (Business != null) { _context.Business.Remove(Business); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { string email = (value as string).Trim(); IBusinessRepository _context = (IBusinessRepository)validationContext.GetService(typeof(IBusinessRepository)); Models.Business obj = (Models.Business)validationContext.ObjectInstance; List <Models.Business> list = (List <Models.Business>)_context.FindAllsEmals(email); if (list.Count > 1) { return(new ValidationResult("E-mail já cadastrado")); } if (list.Count == 1 && obj.Id != list[0].Id) { return(new ValidationResult("E-mail já cadastrado")); } return(ValidationResult.Success); }
public ActionResult Index() { Models.Business lovelyThreading = new Models.Business() { Name = "Lovely Threading", Location = "554 Washington St, Canton, MA, 02021", ServiceProvided = new List <Models.ServiceProvided>() { new Models.ServiceProvided() { ID = 1, Name = "Threading", Price = 8, ServiceTime = new TimeSpan(0, 10, 0), Description = "Eyebrows threading" } } }; return(View(lovelyThreading)); }
private void DeleteBusiness_Click(object sender, RoutedEventArgs e) { try { Models.Business bus = context.Business.Find(ind); context.Business.Remove(bus); context.SaveChanges(); FillTable(); DeleteBusiness.IsEnabled = false; BusinessPerson.Text = ""; FlowDocument flow = new FlowDocument(new Paragraph(new Run(""))); BusinessTextWork.Document = flow; FillTable(); DeleteBusiness.IsEnabled = false; ChangeBusiness.IsEnabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } }