// clean up the database public override void Clear() { base.Clear(); var cacheEntry = db.UserTokenCaches.FirstOrDefault(c => c.webUserUniqueId == userId); db.UserTokenCaches.Remove(cacheEntry); db.SaveChanges(); }
public static void AddUser(string userName, string firstName, string lastName, string emailAddress, string password, int roleID) { try { using (var ctxt = new AuthenticationEntities()) { ctxt.Users.Add(new User() { UserName = userName, FirstName = firstName, LastName = lastName, Password = password, RoleID = roleID, EmailAddress = emailAddress }); ctxt.SaveChanges(); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
/// <summary> /// Api for post data from body. /// </summary> /// <param name="authDetail"></param> /// <returns></returns> public IHttpActionResult PostAuthDetail([FromBody] AuthDetail authDetail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } entityObj.AuthDetails.Add(authDetail); try { entityObj.SaveChanges(); } catch (DbUpdateException) { if (AuthDetailExists(authDetail.username)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = authDetail.username }, authDetail)); }
//regitering new public bool Register(VM.ApplicationUser userData) { bool result = false; try { //register new user var userInfo = _Context.ApplicationUsers.Where(x => x.EmailID == userData.EmailID || x.UserName == userData.UserName).FirstOrDefault(); if (userInfo == null) { ApplicationUser User = new ApplicationUser(); Mapper.Map(userData, User); User.CreatedOn = DateTime.Now; _Context.ApplicationUsers.Add(User); _Context.SaveChanges(); result = true; } return(result); } catch (Exception ex) { return(result); } }