public IActionResult addbike([FromBody] ProductInfo newprod) { System.Console.WriteLine(newprod); // newprod.UserId=19; if (ModelState.IsValid) { _context.Add(newprod); _context.SaveChanges(); return(Json(true)); } else { ViewBag.errors = ModelState.Values; ViewBag.status = "prodaddfail"; return(Json(false)); } }
public IActionResult register([FromBody] Userrecord user) { System.Console.WriteLine(user.FirstName); System.Console.WriteLine("In RegController"); if (ModelState.IsValid) { System.Console.WriteLine("In Regmodelvalid"); List <Userrecord> existinguser = _context.user.Where(u => u.EmailAddress == user.EmailAddress).ToList(); System.Console.WriteLine("In Regmodelvalid"); if (existinguser.Count == 0) { Userrecord newUser = new Userrecord { FirstName = user.FirstName, LastName = user.LastName, EmailAddress = user.EmailAddress, }; // newUser.Password = Hasher.HashPassword(newUser, user.Password); newUser.Password = user.Password; _context.Add(newUser); _context.SaveChanges(); Userrecord logUser = _context.user.SingleOrDefault(u => u.EmailAddress == user.EmailAddress); HttpContext.Session.SetInt32("uid", logUser.UserId); System.Console.WriteLine("here"); return(Json(true)); } else { System.Console.WriteLine("In firstelse"); ViewBag.status = "regfailspecific"; ViewBag.regerror = "User already exists"; return(Json(false)); } } else { System.Console.WriteLine("In secondelse"); ViewBag.errors = ModelState.Values; ViewBag.status = "regfail"; return(Json(false)); } // return Json(true); }