public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Business,DateIn,DateOut")] Visitors visitors) { if (ModelState.IsValid) { _context.Add(visitors); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(visitors)); }
public async Task <IActionResult> Create([Bind("Id,Name,Department")] StaffNames staffNames) { if (ModelState.IsValid) { _context.Add(staffNames); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(staffNames)); }
public void CreateVisitorLogin(Visitors visitors) { if (ModelState.IsValid) { //add in login time visitors.DateIn = DateTime.Now; _context.Add(visitors); _context.SaveChangesAsync(); } // return CreatedAtAction("GetVisitors", new { id = visitors.Id }, visitors); }
public IActionResult Create([Bind("Id,Name,Department,VisitorCount")] StaffNamesDTO staffNamesDTO) { var staffNames = new StaffNames() { Id = staffNamesDTO.Id, Name = staffNamesDTO.Name, Department = staffNamesDTO.Department, VisitorCount = staffNamesDTO.VisitorCount }; if (ModelState.IsValid) { _context.Add(staffNames); _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(staffNamesDTO)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Business,DateIn,DateOut")] Visitor visitor) { visitor.DateIn = DateTime.Now; visitor.DateOut = DateTime.Now; StaffNames myNames = new StaffNames(); myNames.Id = 4; myNames.Department = "asasa"; myNames.Name = "Howard the axe killer"; myNames.VisitorCount = 2; visitor.StaffName = myNames; if (ModelState.IsValid) { _context.Add(visitor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(visitor)); }
public async Task <IActionResult> Create([Bind("Id,ReturningVisitor,FirstName,LastName,Business,DateIn,DateOut,StaffName")] CreateVisitorVM createVisitorVM) { if (createVisitorVM.ReturningVisitor != null) { //returning visitor has 2 numbers visitor ID and Staff ID string[] RVID = createVisitorVM.ReturningVisitor.Split(" "); //get the entry at that ID int id = Convert.ToInt32(RVID[0]); //get the details of the returning visitor without the ID Visitor newvisitor = (Visitor)_context.Visitor .Where(v => v.Id == id) .Select(v => new Visitor { FirstName = v.FirstName, LastName = v.LastName, StaffName = v.StaffName, Business = v.Business }) .SingleOrDefault(); int staffid = 0; if (RVID[1] == String.Empty) { // Get the staff ID from the DB via the name var StaffID = _context.StaffNames.Where(s => s.Name == newvisitor.StaffName.ToString()).Select(s => s.Id).SingleOrDefaultAsync(); staffid = Convert.ToInt16(StaffID); } else { //its a returning visitor just get the ID from the array staffid = Convert.ToInt16(RVID[1]); } //increment the staff count by 1 _dataBaseCalls.IncrementStaffCount(staffid); //reset the id to 0 to make it a new entry // newvisitor.Id = 0; //add the date in to the visitor newvisitor.DateIn = DateTime.Now; _context.Add(newvisitor); await _context.SaveChangesAsync(); return(Redirect("~/Home/Index")); } if (ModelState.IsValid) { //increment staff count by 1 _dataBaseCalls.IncrementStaffCount(createVisitorVM.StaffName.Id); //add the date in to the visitor createVisitorVM.DateIn = DateTime.Now; Visitor visitor = new Visitor(); visitor.Business = createVisitorVM.Business; visitor.DateIn = createVisitorVM.DateIn; visitor.DateOut = createVisitorVM.DateOut; visitor.FirstName = createVisitorVM.FirstName; visitor.LastName = createVisitorVM.LastName; visitor.StaffName = createVisitorVM.StaffName; _context.Add(visitor); await _context.SaveChangesAsync(); return(Redirect("~/Home/Index")); // return RedirectToAction(nameof(Index)); } return(NotFound()); }