public async Task <IActionResult> PostClientProfile(ClientProfileRequest userRequest) { ClientProfileService service = new ClientProfileService(_context); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(service.Add(userRequest).ToJson()); }
public ResponseClass Add(ClientProfileRequest request) { var res = new ResponseClass(); try { var users = _context.Users.Where(a => a.Id == request.UserId).FirstOrDefault(); if (users == null) { res.data = "User not found with the Id"; return(res); } var alreadyExists = _context.ClientProfile.Where(a => a.Users.Id == request.UserId).FirstOrDefault(); if (alreadyExists != null) { res.data = "User not found with the Id"; return(res); } var clientProfile = new ClientProfile() { Address = request.Address, Mobile = request.Mobile, Name = request.Name, IsActive = true, CreatedDate = new DateTime(), UpdatedDate = new DateTime(), Users = users }; _context.ClientProfile.Add(clientProfile); _context.SaveChanges(); res.status = true; res.data = request.Mobile; return(res); } catch (Exception ex) { res.status = false; res.data = ex.Message; return(res); } }
public async Task <IActionResult> Register(UserRequest userRequest) { var res = new ResponseClass(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (string.IsNullOrEmpty(userRequest.Mobile)) { res.status = false; res.data = 0; } try { var alreadyExists = _context.Users.Where(a => a.Mobile == userRequest.Mobile).FirstOrDefault(); if (alreadyExists != null) { res.status = true; res.data = alreadyExists.Id; } else { var users = new Users() { Address = userRequest.Address, Mobile = userRequest.Mobile, UserType = userRequest.UserType, Name = userRequest.Name, IsActive = true, CreatedDate = new DateTime(), UpdatedDate = new DateTime() }; _context.Users.Add(users); var _res = _context.SaveChanges(); } var lastid = _context.Users.Where(a => a.Mobile == userRequest.Mobile).FirstOrDefault(); res.status = true; res.data = lastid.Id; if (userRequest.UserType == 2) { ClientProfileService service = new ClientProfileService(_context); var clientRequest = new ClientProfileRequest() { Mobile = userRequest.Mobile, UserId = lastid.Id }; service.Add(clientRequest); } else { LawyerProfileService service = new LawyerProfileService(_context); var clientRequest = new LawyerProfileRequest() { Mobile = userRequest.Mobile, UserId = lastid.Id }; service.Add(clientRequest); } return(res.ToJson()); } catch (Exception ex) { res.status = false; res.data = ex.Message; return(CreatedAtAction("GetUsers", res)); } }