예제 #1
0
        /// <summary>
        /// Retrieve City Details
        /// </summary>
        /// <returns></returns>
        public IList<CityPoint> RetrieveCityDetails()
        {
            IList<CityPoint> cityList = new List<CityPoint>();
            DataAccessDataContext ctx = new DataAccessDataContext();
            var cities = ctx.Cities.Where(@w => @w.Active).ToList();

            foreach (var city in cities)
            {
                cityList.Add(new CityPoint { Name = city.Name, Code = city.Number, Server = city.Server, GCMSenderId = city.GCMSenderId });
            }

            return cityList;
        }
예제 #2
0
        public int AuthenticateUser(string key)
        {
            DataAccessDataContext ctx = new DataAccessDataContext();
            bool isExists = ctx.Auths.Where(@w => @w.Key == key).Count() == 1;

            if (isExists)
            {
                return 201;
            }
            else
            {
                return 101;
            }
        }
예제 #3
0
        public int SignupUser(string name, string mobile, string cityCode)
        {
            DataAccessDataContext ctx = new DataAccessDataContext();
            bool isExists = ctx.Users.Where(@w => @w.Name == name && @w.Mobile == mobile).Count() == 1;

            if (isExists)
            {
                return 102;
            }
            else
            {
                Random rm = new Random();
                int vc = rm.Next(1000, 9999);
                SendSMS(mobile, vc);
                return vc;
            }
        }
예제 #4
0
        public int DeleteAllUsers()
        {
            DataAccessDataContext ctx = new DataAccessDataContext();

            var userList = ctx.Users.ToList();
            ctx.Users.DeleteAllOnSubmit(userList);

            var addressList = ctx.Addresses.ToList();
            ctx.Addresses.DeleteAllOnSubmit(addressList);

            var authList = ctx.Auths.ToList();
            ctx.Auths.DeleteAllOnSubmit(authList);

            ctx.SubmitChanges();

            return 204;
        }
예제 #5
0
        /// <summary>
        /// DeleteUser
        /// </summary>
        /// <param name="mobile"></param>
        public int DeleteUser(string mobile)
        {
            DataAccessDataContext ctx = new DataAccessDataContext();
            var userList = ctx.Users.ToList();
            foreach (var user in userList)
            {
                ctx.Users.DeleteOnSubmit(user);
            }

            var addressList = ctx.Addresses.ToList();
            foreach (var address in addressList)
            {
                ctx.Addresses.DeleteOnSubmit(address);
            }

            var authList = ctx.Auths.ToList();

            foreach (var auth in authList)
            {
                ctx.Auths.DeleteOnSubmit(auth);
            }

            ctx.SubmitChanges();

            return 204;
        }
예제 #6
0
        /// <summary>
        /// RegisterKey
        /// </summary>
        /// <param name="key"></param>
        /// <param name="mobileNumber"></param>
        /// <returns></returns>
        public int RegisterUserKey(string key, string mobile)
        {
            DataAccessDataContext ctx = new DataAccessDataContext();
            var user = ctx.Users.Where(@w => @w.Mobile == mobile).First();
            var authSingle = ctx.Auths.Where(@w => @w.UserId == user.Id).First();

            authSingle.Key = key;
            authSingle.ApplicationId = key.Replace(user.Name, "").Replace(mobile, "");
            ctx.SubmitChanges();

            return 203;
        }
예제 #7
0
        /// <summary>
        /// Confirm User Signin
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public int ConfirmUserSignin(string mobile, string key)
        {
            DataAccessDataContext ctx = new DataAccessDataContext();
            bool isExists = ctx.Auths.Where(@w => @w.Key == key).Count() == 1;

            if (isExists)
            {
                return 201;
            }
            else
            {
                Random rm = new Random();
                int vc = rm.Next(1000, 9999);
                SendSMS(mobile, vc);
                return vc;
            }
        }
예제 #8
0
 /// <summary>
 /// RetrieveReferCode
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public string RetrieveReferCode(string key)
 {
      DataAccessDataContext ctx = new DataAccessDataContext();
      return ctx.Auths.Where(@w => @w.Key == key).Select(@s => @s.REFCODE).First();
 }
예제 #9
0
        /// <summary>
        /// Signin User
        /// </summary>
        /// <param name="name"></param>
        /// <param name="mobile"></param>
        /// <param name="cityCode"></param>
        /// <returns></returns>
        public int SigninUser(string name, string mobile, string cityCode, string gcmToken)
        {
            DataAccessDataContext ctx = new DataAccessDataContext();
            var user = ctx.Users.Where(@w => @w.Name == name && @w.Mobile == mobile);
            bool isExists = user.Count() == 1;

            if (!isExists)
            {
                return 103;
            }
            else
            {
                if (!string.IsNullOrEmpty(gcmToken))
                {
                    var authSingle = ctx.Auths.Where(@w => @w.UserId == user.First().Id).First();
                    authSingle.GCMToken = gcmToken;
                    ctx.SubmitChanges();
                }

                return 202;
            }
        }
예제 #10
0
 /// <summary>
 /// Retrieve City
 /// </summary>
 /// <param name="cityCode"></param>
 /// <param name="ctx"></param>
 /// <returns></returns>
 private static Guid RetrieveCity(string cityCode, DataAccessDataContext ctx)
 {
     //Get City
     Guid cityId = ctx.Cities.Where(@w => @w.Number == cityCode).First().Id;
     return cityId;
 }
예제 #11
0
        /// <summary>
        /// InsertAddressMetaData
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        private static Guid InsertAddressMetaData(DataAccessDataContext ctx, Guid userId)
        {
            //Insert Address
            Guid addressId = Guid.NewGuid();
            Address address = new Address
            {
                Id = addressId,
                HouseNo = "",
                Street = "",
                Locality = "",
                WardId = Guid.NewGuid(),
                PINCODE = 560093,
                Registered = false,
                UserId = userId
            };

            ctx.Addresses.InsertOnSubmit(address);
            ctx.SubmitChanges();
            return addressId;
        }
예제 #12
0
        /// <summary>
        /// GenerateReferralCode
        /// </summary>
        /// <returns></returns>
        private string GenerateReferralCode()
        {
            bool flag = false;
            const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            Random rm = new Random();
            string refCode = "";
            DataAccessDataContext ctx = new DataAccessDataContext();

            while (!flag)
            {
                refCode = new string(Enumerable.Repeat(alphabet, 4).Select(@s => @s[rm.Next(4)]).ToArray()) + "01";
                flag = ctx.Auths.Where(@s => @s.REFCODE.Equals(refCode)).Count() == 0;
            }

            return refCode;
        }
예제 #13
0
        /// <summary>
        /// InsertAuthSingleMetaData
        /// </summary>
        /// <param name="applicationId"></param>
        /// <param name="key"></param>
        /// <param name="ctx"></param>
        /// <returns></returns>
        private static Guid InsertAuthSingleMetaData(string applicationId, string gcmToken, string refCode, string genRefCode, string key, DataAccessDataContext ctx, Guid userId)
        {
            //Insert Auth key
            Guid authId = Guid.NewGuid();
            Auth authSingle = new Auth
            {
                Id = authId,
                GCMToken = gcmToken,
                REFCODE = genRefCode,
                Key = key,
                ApplicationId = applicationId,
                UserId = userId
            };

            ctx.Auths.InsertOnSubmit(authSingle);
            ctx.SubmitChanges();
            return authId;
        }
예제 #14
0
        /// <summary>
        /// InsertUserMetaData
        /// </summary>
        /// <param name="name"></param>
        /// <param name="mobile"></param>
        /// <param name="ctx"></param>
        /// <param name="cityId"></param>
        /// <param name="addressId"></param>
        /// <param name="authId"></param>
        private static Guid InsertUserMetaData(string name, string mobile, DataAccessDataContext ctx, Guid cityId)
        {
            //Insert User Information.
            Guid userId = Guid.NewGuid();
            User user = new User
            {
                Id = userId,
                Name = name,
                Mobile = mobile,
                CityId = cityId,
                Active = true,
            };

            ctx.Users.InsertOnSubmit(user);
            ctx.SubmitChanges();

            return userId;
        }
예제 #15
0
        /// <summary>
        /// InsertRegistrationPoints
        /// </summary>
        /// <param name="userId"></param>
        private void InsertRegistrationPoints(Guid userId)
        {
            DataAccessDataContext ctx = new DataAccessDataContext();
            var urPoints = ctx.PointConfigurations.Where(@w => @w.Type == "UR").First();

            Point point = new Point
            {
                Id = Guid.NewGuid(),
                Point1 = urPoints.Point,
                UserId = userId
            };

            ctx.Points.InsertOnSubmit(point);
            ctx.SubmitChanges();
        }
예제 #16
0
        /// <summary>
        /// Confirm User Signup
        /// </summary>
        /// <param name="name"></param>
        /// <param name="mobile"></param>
        /// <param name="cityCode"></param>
        /// <param name="applicationId"></param>
        /// <returns></returns>
        public string ConfirmUserSignup(string name, string mobile, string cityCode, string applicationId, string gcmToken, string refCode)
        {
            string key = string.Empty;

            try
            {
                string referralCode = GenerateReferralCode();
                key = cityCode + name + mobile + applicationId;
                DataAccessDataContext ctx = new DataAccessDataContext();
                Guid cityId = RetrieveCity(cityCode, ctx);
                Guid userId = InsertUserMetaData(name, mobile, ctx, cityId);
                Guid addressId = InsertAddressMetaData(ctx, userId);
                Guid authId = InsertAuthSingleMetaData(applicationId, gcmToken, refCode, referralCode, key, ctx, userId);
                InsertRegistrationPoints(userId);

                if (!string.IsNullOrEmpty(gcmToken))
                {
                    SendNotification("UR", gcmToken, referralCode);
                }

                return key;

            }
            catch (Exception ex)
            {
                key = "100";
            }

            return key;
        }