Ejemplo n.º 1
0
        public IHttpActionResult PostData([FromBody] Model.User userData)
        {
            ResponseMsg msgRes = new ResponseMsg();

            try
            {
                VM.ApplicationUser regData = new VM.ApplicationUser();
                regData.EmailID = userData.EmailID;
                //regData.Password = Encoding.UTF8.GetBytes(userData.Password);
                regData.Password = userData.Password;
                regData.UserName = userData.UserName;
                regData.RoleId   = userData.RoleId;
                if (accountService.Register(regData))
                {
                    msgRes = new ResponseMsg {
                        Message = "User registered successfully", Response = "success", ResponseCode = 101
                    };
                }
                else
                {
                    msgRes = new ResponseMsg {
                        Message = "User already exists", Response = "failure", ResponseCode = 102
                    };
                }
            }
            catch (Exception ex)
            {
                msgRes.Message      = ex.Message;
                msgRes.Response     = "exception";
                msgRes.ResponseCode = 404;
                return(Ok(msgRes));
            }

            return(Ok(msgRes));
        }
Ejemplo n.º 2
0
        //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);
            }
        }