Example #1
0
        public async Task <IActionResult> Post()
        {
            try
            {
                var tmpData = new MstUser
                {
                    Id       = Guid.NewGuid(),
                    Username = "******",
                    Password = Encryptor.Encrypt("dummy"),
                    Name     = "i'm dummy Asnyc",
                    Status   = true
                };

                // Create with non Async
                //_userService.Save(tmpData);

                // Create with Async
                await _userService.SaveAsync(tmpData);

                return(Ok(new ApiResponse(200)));
            }
            catch (Exception ex)
            {
                return(BadRequest(new ApiResponse(400, ex.Message)));
            }
        }
Example #2
0
        public JsonResult CanLogin(MstUser user)
        {
            var userRepos = new Repository.MstUser();
            var result    = userRepos.IsLoginSuccess(user.UserName, user.Password);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public async Task <IActionResult> Edit(int id, [Bind("PkUserId,Fname,Lname,Email,Contact,Pswd,Dob,CreatedDate,FkRoleId,IsActive,IsDeleted")] MstUser mstUser)
        {
            if (id != mstUser.PkUserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(mstUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MstUserExists(mstUser.PkUserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(mstUser));
        }
        public HttpResponseMessage UpdateMstUser(MstUser user)
        {
            try
            {
                var MstUserData = from d in db.MstUsers
                                  where d.Id == Convert.ToInt32(user.Id)
                                  select d;

                if (MstUserData.Any())
                {
                    var UpdateUserData = MstUserData.FirstOrDefault();

                    UpdateUserData.FullName = user.FullName;
                    UpdateUserData.Status   = user.Status;

                    db.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Example #5
0
        public IEnumerable <MstUser> UpdateUser(MstUser user)
        {
            IEnumerable <MstUser> allUsers = null;
            MstUser existingUser           = uow.UserRepository.Get(user.Id);

            if (existingUser != null)
            {
                existingUser.Address      = user.Address;
                existingUser.AltPhone     = user.Address;
                existingUser.CityId       = user.CityId;
                existingUser.ModifiedBy   = this.GetUserId("");
                existingUser.IsActive     = user.IsActive;
                existingUser.ModifiedDate = DateTime.Now;
                existingUser.Name         = user.Name;
                existingUser.Phone        = user.Phone;
                existingUser.Pincode      = user.Pincode;

                // uow.update
                if (uow.Complete())
                {
                    allUsers = GetAllUsers();
                }
            }

            return(allUsers);
        }
Example #6
0
        public static async Task Main(string[] args)
        {
            using (var client = new HttpClient())
            {
                //    var uri = (@"http://192.168.1.2/posserver/MstCustomer/GetCustomer");
                //    var uri = (@"http://localhost/posserver/MstCustomer/GetCustomers");
                var uri = (@"http://localhost/posserver/MstUser/canLogin");

                var user = new MstUser()
                {
                    UserName = "******",
                    Password = "******"
                };


                var paramContent = JsonConvert.SerializeObject(user);
                var buffer       = System.Text.Encoding.UTF8.GetBytes(paramContent);
                var byteContent  = new ByteArrayContent(buffer);

                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                var responseContent = await client.PostAsync(uri, byteContent);

                var response = await responseContent.Content.ReadAsStringAsync();

                var customers = JsonConvert.DeserializeObject <bool>(response);

                Console.WriteLine(customers);

                Console.Read();
            }
        }
 public DBResult <object> DAL_SaveUserDetails(MstUser user)
 {
     try
     {
         using (SqlConnection conn = new SqlConnection(ConnectionString))
         {
             conn.Open();
             using (SqlCommand cmd = new SqlCommand("usp_GetAddUpdateUser", conn))
             {
                 cmd.CommandType    = CommandType.StoredProcedure;
                 cmd.CommandTimeout = 60;
                 cmd.Parameters.Add(new SqlParameter("@UserId", user.UserId));
                 cmd.Parameters.Add(new SqlParameter("@CountryId", user.CountryId));
                 cmd.Parameters.Add(new SqlParameter("@Gender", user.Gender));
                 cmd.Parameters.Add(new SqlParameter("@LanguageId", user.LanguageId));
                 cmd.Parameters.Add(new SqlParameter("@Remarks", user.Remarks));
                 cmd.Parameters.Add(new SqlParameter("@IsAdd", false));
                 cmd.Parameters.Add(new SqlParameter("@IsEdit", true));
                 cmd.ExecuteNonQuery();
             }
             conn.Close();
         }
         return(new DBResult <object>
         {
             TransactionResult = true
         });
     }
     catch (Exception ex)
     {
         return(new DBResult <object>
         {
             TransactionResult = false
         });
     }
 }
 public DBContextResult <MstUser> AddUserUsingEF(MstUser p_MST_User)
 {
     return(ExecuteEntityFrameworkMethod <MstUser, MstUser>(db, (DataContext, P_MST_UserInfo) =>
     {
         DataContext.MstUsers.Add(P_MST_UserInfo);
         DataContext.SaveChanges();
         return p_MST_User;
     }, p_MST_User));
 }
        public async Task <IActionResult> Create([Bind("PkUserId,Fname,Lname,Email,Contact,Pswd,Dob,CreatedDate,FkRoleId,IsActive,IsDeleted")] MstUser mstUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mstUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mstUser));
        }
Example #10
0
 public HttpResponseMessage UpdateUsers(MstUser user)
 {
     if (user != null)
     {
         return(Request.CreateResponse(HttpStatusCode.Accepted, UserService.UpdateUser(user)));
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "Model is null."));
     }
 }
Example #11
0
        public IEnumerable <MstUser> AddUser(MstUser user)
        {
            IEnumerable <MstUser> allUsers = null;

            user.CreatedDate  = DateTime.Now;
            user.ModifiedDate = DateTime.Now;
            user.ModifiedBy   = this.GetUserId("");
            uow.UserRepository.Add(user);

            if (uow.Complete())
            {
                allUsers = GetAllUsers();
            }

            return(allUsers);
        }
Example #12
0
        public IEnumerable <MstUser> DeleteUser(int userId)
        {
            IEnumerable <MstUser> allUsers = null;

            MstUser existingUser = uow.UserRepository.Get(userId);

            if (existingUser != null)
            {
                uow.UserRepository.Remove(existingUser);
                if (uow.Complete())
                {
                    allUsers = GetAllUsers();
                }
            }

            return(allUsers);
        }
        public DBContextResult <DataTable> AddUserUsingAdoNet(MstUser p_MST_User)
        {
            using SqlConnection conn = new SqlConnection("Server=DESKTOP-2KLD6BE;Database=DelegateDemo;User ID=Admin;pwd=admin123");
            conn.Open();
            using SqlCommand cmd = new SqlCommand("usp_AddUser", conn);
            cmd.Parameters.Add(new SqlParameter("@FirstName", p_MST_User.FirstName));
            cmd.Parameters.Add(new SqlParameter("@LastName", p_MST_User.LastName));
            cmd.Parameters.Add(new SqlParameter("@MobileNumber", p_MST_User.MobileNumber));
            using var da    = new SqlDataAdapter(cmd);
            cmd.CommandType = CommandType.StoredProcedure;
            DBContextResult <DataTable> result = ExecuteAdoNetMethod <SqlDataAdapter, DataTable>(da, (DataAdapter) =>
            {
                DataTable DataTable = new DataTable();
                da.Fill(DataTable);
                return(DataTable);
            });

            conn.Close();
            return(result);
        }
Example #14
0
 public DBResult <DataTable> DAL_Registration(MstUser p_UserDetailsModel)
 {
     try
     {
         DataTable table = new DataTable();
         using (SqlConnection conn = new SqlConnection(ConnectionString))
         {
             conn.Open();
             using (SqlCommand cmd = new SqlCommand("usp_GetAddUpdateUser", conn))
             {
                 cmd.CommandTimeout = 60;
                 cmd.Parameters.Add(new SqlParameter("@FirstName", p_UserDetailsModel.FirstName));
                 cmd.Parameters.Add(new SqlParameter("@LastName", p_UserDetailsModel.LastName));
                 cmd.Parameters.Add(new SqlParameter("@MobileNumber", p_UserDetailsModel.MobileNumber));
                 cmd.Parameters.Add(new SqlParameter("@Email", p_UserDetailsModel.Email));
                 cmd.Parameters.Add(new SqlParameter("@Password", p_UserDetailsModel.Password));
                 cmd.Parameters.Add(new SqlParameter("@IsAdd", true));
                 cmd.Parameters.Add(new SqlParameter("@IsEdit", false));
                 using (var da = new SqlDataAdapter(cmd))
                 {
                     cmd.CommandType = CommandType.StoredProcedure;
                     da.Fill(table);
                 }
             }
             conn.Close();
         }
         return(new DBResult <DataTable>
         {
             TransactionResult = true,
             Data = table
         });
     }
     catch (Exception ex)
     {
         return(new DBResult <DataTable>
         {
             TransactionResult = false
         });
     }
 }
        public Int32 PostMstUser(MstUser user)
        {
            try
            {
                Data.MstUser newMstUser = new Data.MstUser()
                {
                    Username = user.Username,
                    FullName = user.FullName,
                    Password = user.Password,
                    Status   = user.Status,
                    AspNetId = user.AspNetId
                };

                db.MstUsers.InsertOnSubmit(newMstUser);
                db.SubmitChanges();

                return(newMstUser.Id);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(0);
            }
        }
Example #16
0
        private async void CmdLogin_Clicked(object sender, EventArgs e)
        {
            var user = new MstUser
            {
                UserName = UserName.Text,
                Password = Password.Text
            };

            if (user.Password == "pass")
            {
                SettingsRepository.CreateLocalSettingsDB();

                await Navigation.PushAsync(new Settings());

                return;
            }

            try
            {
                LoginActivityIndicator.IsRunning = true;
                LoginActivityIndicator.IsVisible = true;

                LoginText.Text = "Logging in, please wait for a moment!";

                var login = await ApiRequest <MstUser, MstUser> .PostRead("MstUser/CanLogin", user);

                if (login != null && login.Id != 0)
                {
                    SettingsRepository.UpdateLocalSettingsDB(login);

                    await Navigation.PushAsync(new AppMenu());

                    Navigation.RemovePage(this);
                }
                else
                {
                    if (loginAttemptCount > 0)
                    {
                        LoginText.Text      = $"Invalid username or password!, attempt {loginAttemptCount}";
                        LoginText.TextColor = Color.Red;

                        if (loginAttemptCount > 9)
                        {
                            await Application.Current.MainPage.DisplayAlert("POS", "App will be terminated", "Ok");

                            Environment.Exit(0);
                        }
                    }
                    else
                    {
                        LoginText.Text = "Invalid username or password!";
                    }

                    loginAttemptCount++;
                }

                LoginActivityIndicator.IsRunning = false;
                LoginActivityIndicator.IsVisible = false;
            }
            catch (Exception ex)
            {
                SettingsRepository.CreateLocalSettingsDB();

                LoginText.Text = $"{ex.Message}";

                LoginActivityIndicator.IsRunning = false;
                LoginActivityIndicator.IsVisible = false;
            }
        }
        public async Task <Tuple <int, long> > UserRegisterNewAccount(string LoginID, string FullName, string Password, string Email, string Phonenumber, string CountryCode, string DOB, int Gender, string Upline)
        {
            using var dbContextTransaction = _db.Database.BeginTransaction();
            try
            {
                int temp       = 1;
                var RandomCode = "";
                do
                {
                    var tempcode = _common_services.GenerateRandomNumber(10);
                    if (IsRefcodeExist(tempcode))
                    {
                        temp = 1;
                    }
                    else
                    {
                        RandomCode = tempcode;
                        temp       = 0;
                    }
                }while (temp == 1);

                var gamelogin = "******" + RandomCode;

                if (Upline != null && !IsRefcodeExist(Upline))
                {
                    return(new Tuple <int, long>(Models_General.ERR_UPLINE_REFERCODE_NOT_EXIST, 0));
                }
                else if (IsUsernameExist(LoginID))
                {
                    return(new Tuple <int, long>(Models_General.ERR_USERNAME_EXIST, 0));
                }
                else if (IsPhoneExist(Phonenumber))
                {
                    return(new Tuple <int, long>(Models_General.ERR_PHONENUMBER_EXIST, 0));
                }
                else if (IsEmailExist(Email))
                {
                    return(new Tuple <int, long>(Models_General.ERR_EMAIL_EXIST, 0));
                }

                //This will be the main table that all references will be linked to this MemberSrno so we need it to be the first table to store in our database and get the MemberSrno
                var UserAccount = new MstUserAccount
                {
                    LoginId      = LoginID,
                    Password     = Password,
                    Status       = "ACTIVE",
                    AccountType  = "MEMBER",
                    GameRegister = 0
                };
                //Add this into database first so that we can retrive the MemberSrno
                _db.MstUserAccount.Add(UserAccount);
                _db.SaveChanges();

                //Register a new account into our system

                var UserDetails = new MstUser {
                };


                if (Upline != null && Upline != "")
                {
                    var UplineDetails = _db.MstUser.Where(x => x.RefCode.Equals(Upline)).FirstOrDefault();
                    var UplineAccount = _db.MstUserAccount.Where(x => x.MemberSrno.Equals(UplineDetails.MemberSrno)).FirstOrDefault();

                    UserDetails = new MstUser
                    {
                        MemberSrno   = UserAccount.MemberSrno,
                        Name         = FullName,
                        Email        = Email,
                        Phone        = Phonenumber,
                        Country      = CountryCode,
                        DoB          = DOB,
                        Gender       = Gender,
                        RegisterDate = DateTime.Now,
                        RefCode      = RandomCode,
                        Upline       = UplineAccount.LoginId,
                        UplineId     = UplineAccount.MemberSrno,
                    };
                }
                else
                {
                    UserDetails = new MstUser
                    {
                        MemberSrno   = UserAccount.MemberSrno,
                        Name         = FullName,
                        Email        = Email,
                        Phone        = Phonenumber,
                        Country      = CountryCode,
                        DoB          = DOB,
                        Gender       = Gender,
                        RegisterDate = DateTime.Now,
                        RefCode      = RandomCode,
                    };
                }

                var UserCashWallet = new MstUserWallet
                {
                    MemberSrno = UserAccount.MemberSrno,
                    CashCredit = 0
                };

                //Set defualt password for game account
                var _GamePassword = "******";

                var UserGameAccount = new MstUserGameAccount
                {
                    MemberSrno      = UserAccount.MemberSrno,
                    GamePassword    = _GamePassword,
                    GameId          = gamelogin,
                    CreatedDateTime = DateTime.Now,
                };
                var UserGameWallet = new MstUserGameWallet
                {
                    MemberSrno = UserAccount.MemberSrno,
                    GameId     = gamelogin,
                    GameCredit = 0,
                };

                //Call 998 API to create a agame account
                var result = await _intergration.CreateNewPlayer(gamelogin, FullName, Email, Phonenumber, DOB, _GamePassword, CountryCode, Gender);

                if (result.Error == 0)
                {
                    //API Successfully Created an Account from the thrid party side then only allow to create an account into our database
                    _db.MstUser.Add(UserDetails);
                    _db.MstUserWallet.Add(UserCashWallet);
                    _db.MstUserGameAccount.Add(UserGameAccount);
                    _db.MstUserGameWallet.Add(UserGameWallet);
                    UserAccount.GameRegister = 1;
                    await _db.SaveChangesAsync();

                    dbContextTransaction.Commit();

                    return(new Tuple <int, long>(Models_General.SUCC_CREATE_ACCOUNT, UserAccount.MemberSrno));
                }
                else
                {
                    _db.MstUser.Add(UserDetails);
                    _db.MstUserWallet.Add(UserCashWallet);
                    _db.MstUserGameAccount.Add(UserGameAccount);
                    _db.MstUserGameWallet.Add(UserGameWallet);
                    UserAccount.GameRegister = 2;
                    await _db.SaveChangesAsync();

                    dbContextTransaction.Commit();

                    return(new Tuple <int, long>(Models_General.SUCC_CREATE_ACCOUNT_WITHOUT_GAME_ACCOUNT, UserAccount.MemberSrno));
                }
            }
            catch (Exception ex)
            {
                dbContextTransaction.Rollback();


                var new_error = new LogErrorSystem
                {
                    Title           = "User Register New Account",
                    Details         = ex.Message + "/" + ex.StackTrace,
                    Context         = _accessor.ActionContext.HttpContext.Connection.RemoteIpAddress.ToString(),
                    CreatedDateTime = DateTime.Now,
                };
                _db.LogErrorSystem.Add(new_error);
                _db.SaveChanges();
                return(new Tuple <int, long>(Models_General.ERR_SERVER_BUSY_INTERNAL_ERROR, 0));
            }
        }