示例#1
0
        public async Task <IActionResult> PutMapUsersSettings([FromRoute] int id, [FromBody] MapUsersSettings mapUsersSettings)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != mapUsersSettings.UserSettingId)
            {
                return(BadRequest());
            }

            _context.Entry(mapUsersSettings).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MapUsersSettingsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <IActionResult> PostMapUsersSettings([FromBody] MapUsersSettings mapUsersSettings)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.MapUsersSettings.Add(mapUsersSettings);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetMapUsersSettings", new { id = mapUsersSettings.UserSettingId }, mapUsersSettings));
        }
        public async Task <IActionResult> GetSocialLogin(string accesstoken, string userid, string email, string mobile, string socialType)
        {
            Dictionary <string, object> ClientResponse = new Dictionary <string, object>();

            // Add Response
            ClientResponse.Add("Response", response);

            try
            {
                var mSTUsersSetting = await db.MapUsersSettings.Where(u => u.AccessToken == accesstoken& u.SUserId == userid).FirstOrDefaultAsync();

                if (mSTUsersSetting == null & !String.IsNullOrEmpty(email))
                {
                    int id       = 0;
                    var mSTUsers = await db.MstUsers.Where(u => u.Email == email).FirstOrDefaultAsync();

                    id = mSTUsers.UserId;

                    MapUsersSettings mMapUsersSettings = new MapUsersSettings();

                    mMapUsersSettings.UserId      = id;
                    mMapUsersSettings.AccessToken = accesstoken;
                    mMapUsersSettings.SUserId     = userid;
                    mMapUsersSettings.SPost       = false;
                    switch (socialType)
                    {
                    case "fb":
                        mMapUsersSettings.SettingId = 1;
                        break;

                    case "google":
                        mMapUsersSettings.SettingId = 2;
                        break;

                    case "linkedin":
                        mMapUsersSettings.SettingId = 11;
                        break;
                    }

                    db.MapUsersSettings.Add(mMapUsersSettings);
                    await db.SaveChangesAsync();

                    response.Status  = true;                          // Operation Status Indicator
                    response.Message = "Social login added by email"; // Exception Message
                    response.Result  = mSTUsers;
                    return(Ok(response));
                }
                else if (mSTUsersSetting == null)
                {
                    int id = 0;

                    using (EzyFind_DevContext db = new EzyFind_DevContext())
                    {
                        MstUsers mMstUsers = new MstUsers();
                        mMstUsers.UserName  = email;
                        mMstUsers.Email     = email;
                        mMstUsers.ContactNo = mobile;

                        db.MstUsers.Add(mMstUsers);
                        db.SaveChanges();
                        id = mMstUsers.UserId;

                        MapUsersSettings mMapUsersSettings = new MapUsersSettings();

                        mMapUsersSettings.UserId      = id;
                        mMapUsersSettings.AccessToken = accesstoken;
                        mMapUsersSettings.SUserId     = userid;
                        mMapUsersSettings.SPost       = false;
                        switch (socialType)
                        {
                        case "fb":
                            mMapUsersSettings.SettingId = 1;
                            break;

                        case "google":
                            mMapUsersSettings.SettingId = 2;
                            break;

                        case "linkedin":
                            mMapUsersSettings.SettingId = 11;
                            break;
                        }

                        db.MapUsersSettings.Add(mMapUsersSettings);
                        await db.SaveChangesAsync();

                        var mSTUsers = await db.MstUsers.Where(u => u.UserId == mSTUsersSetting.UserId).FirstOrDefaultAsync();

                        response.Status  = true;                                          // Operation Status Indicator
                        response.Message = "user created & confirmed Social login valid"; // Exception Message
                        response.Result  = mSTUsers;
                        return(Ok(response));
                    }
                }
                else
                {
                    var mSTUsers = await db.MstUsers.Where(u => u.UserId == mSTUsersSetting.UserId).FirstOrDefaultAsync();

                    if (mSTUsers != null)
                    {
                        if (mSTUsers.StatusId == 5)
                        {
                            response.Status  = true;                          // Operation Status Indicator
                            response.Message = "Your account is not active."; // Exception Message
                            response.Result  = null;
                            return(Ok(response));
                        }
                        else
                        {
                            response.Status  = true;                 // Operation Status Indicator
                            response.Message = "Social login valid"; // Exception Message
                            response.Result  = mSTUsers;
                            return(Ok(response));
                        }
                    }
                    else
                    {
                        response.Status  = false;                                                   // Operation Status Indicator
                        response.Message = "An error occurred when retrieving a user. Try again :"; // Exception Message
                        response.Result  = null;
                        return(Ok(response));
                    }
                }
            }
            catch (Exception exception)
            {
                //return BadRequest();

                response.Status  = false;               // Operation Status Indicator
                response.Message = exception.Message;   // Exception Message
                response.Result  = null;
                return(Ok(response));
            }
        }