示例#1
0
        public async Task <IActionResult> PostClientProfile(ClientProfileRequest userRequest)
        {
            ClientProfileService service = new ClientProfileService(_context);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(service.Add(userRequest).ToJson());
        }
示例#2
0
        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));
            }
        }