public async Task <IActionResult> CreateOrCheck(string values) { try { //var content2 = Request; //var content = await Request.ReadFormAsync(); //var a = content[""]; UserInfo model = Newtonsoft.Json.JsonConvert.DeserializeObject <UserInfo>(values); var userIdentity = new Models.Dtos.Identity.UserIdentity(); var entity = await _db.UserInfo.AsNoTracking().FirstOrDefaultAsync(c => c.Phone == model.Phone || c.UserName == model.UserName); if (entity == null) { var result = await _db.UserInfo.AddAsync(model); await _db.SaveChangesAsync(); userIdentity.UserId = result.Entity.ID; userIdentity.Name = result.Entity.Name; userIdentity.Title = result.Entity.Title; userIdentity.Avatar = result.Entity.Avatar; userIdentity.Company = result.Entity.Company; } userIdentity.UserId = entity.ID; userIdentity.Name = entity.Name; userIdentity.Title = entity.Title; userIdentity.Avatar = entity.Avatar; userIdentity.Company = entity.Company; return(Json(userIdentity)); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <IActionResult> Login(string values) { UserInfo model = Newtonsoft.Json.JsonConvert.DeserializeObject <UserInfo>(values); var userIdentity = new Models.Dtos.Identity.UserIdentity(); var entity = await _db.UserInfo.FirstOrDefaultAsync(c => (c.Phone == model.Phone || c.UserName == model.UserName) && c.UserPassword == model.UserPassword); if (entity != null) { entity.LastLoginTime = DateTime.Now; _db.Update(entity); _db.SaveChanges(); } return(Json(entity)); }