Exemplo n.º 1
0
 protected void SetInfo(Membership_Users dbUser, BE.User model)
 {
     if (dbUser != null)
     {
         dbUser.Name        = model.Name;
         dbUser.NRIC        = model.NRIC;
         dbUser.SmartCardId = model.SmartCardId;
         //dbUser.Role = model.Role;
         dbUser.UserId = model.UserId;
         //if (model.RightThumbFingerprint != null)
         //{
         //    byte[] data = new byte[model.RightThumbFingerprint.Length];
         //    for (int i = 0; i < data.Length; i++)
         //    {
         //        data[i] = model.RightThumbFingerprint[i];
         //    }
         //    dbUser.RightThumbFingerprint = data;
         //}
         //if (model.LeftThumbFingerprint != null)
         //{
         //    byte[] data = new byte[model.LeftThumbFingerprint.Length];
         //    for (int i = 0; i < data.Length; i++)
         //    {
         //        data[i] = model.LeftThumbFingerprint[i];
         //    }
         //    dbUser.LeftThumbFingerprint = data;
         //}
         //dbUser.RightThumbFingerprint = model.RightThumbFingerprint;
         //dbUser.LeftThumbFingerprint = model.LeftThumbFingerprint;
         dbUser.Status         = model.Status;
         dbUser.IsFirstAttempt = model.IsFirstAttempt;
     }
 }
Exemplo n.º 2
0
 public EvaluationViewModel(BE.User currentUser)
 {
     ButtonChecked     = false;
     this.CurrentUser  = currentUser;
     this.FullName     = CurrentUser.FirstName + " " + CurrentUser.LastName;
     this.CurrentModel = new EvaluationModel();
 }
Exemplo n.º 3
0
 public BE.User GetUserById(string userId)
 {
     if (EnumAppConfig.IsLocal)
     {
         BE.User user = (from mu in _localUnitOfWork.DataContext.Membership_Users
                         join mur in _localUnitOfWork.DataContext.Membership_UserRoles on mu.UserId equals mur.UserId
                         join mr in _localUnitOfWork.DataContext.Membership_Roles on mur.RoleId equals mr.Id
                         where mu.UserId == userId
                         select new Trinity.BE.User()
         {
             UserId = mu.UserId, Status = mu.Status, SmartCardId = mu.SmartCardId, RightThumbFingerprint = mu.RightThumbFingerprint, LeftThumbFingerprint = mu.LeftThumbFingerprint, Name = mu.Name, NRIC = mu.NRIC, Role = mr.Name, IsFirstAttempt = mu.IsFirstAttempt, AccessFailedCount = mu.AccessFailedCount, User_Photo1 = mu.User_Profiles.User_Photo1, User_Photo2 = mu.User_Profiles.User_Photo2
         }).FirstOrDefault();
         if (user == null)
         {
             user = CallCentralized.Get <BE.User>("User", "GetUserById", "userId=" + userId);
         }
         return(user);
     }
     else
     {
         var user = (from mu in _centralizedUnitOfWork.DataContext.Membership_Users
                     join mur in _centralizedUnitOfWork.DataContext.Membership_UserRoles on mu.UserId equals mur.UserId
                     join mr in _centralizedUnitOfWork.DataContext.Membership_Roles on mur.RoleId equals mr.Id
                     where mu.UserId == userId
                     select new Trinity.BE.User()
         {
             UserId = mu.UserId, Status = mu.Status, SmartCardId = mu.SmartCardId, RightThumbFingerprint = mu.RightThumbFingerprint, LeftThumbFingerprint = mu.LeftThumbFingerprint, Name = mu.Name, NRIC = mu.NRIC, Role = mr.Name, IsFirstAttempt = mu.IsFirstAttempt
         });
         return(user.FirstOrDefault());
     }
 }
Exemplo n.º 4
0
        private void OnGetNameResponse(object sender, GraphResponseEventArgs e)
        {
            JSONObject jSON = e.Response.JSONObject;

            if (jSON != null)
            {
                try
                {
                    string id   = jSON.GetString("id");
                    string nome = jSON.GetString("name");


                    BE.User utente = BLL.GestioneUsers.ReadFacebookUser(id);
                    if (utente == null)
                    {
                        Intent intent = new Intent(BaseContext, typeof(SignupFacebookActivity));
                        intent.PutExtra("FacebookName", nome);
                        intent.PutExtra("FacebookID", id);
                        FacebookProgressBar.Visibility = ViewStates.Gone;
                        StartActivity(intent);
                    }
                    else
                    {
                        BLL.GestioneUsers.LoginFacebookUser(id);
                        FacebookProgressBar.Visibility = ViewStates.Gone;
                        StartActivity(typeof(MainActivity));
                    }
                } catch { }
            }
        }
Exemplo n.º 5
0
 public bool Update(BE.User model)
 {
     if (EnumAppConfig.IsLocal)
     {
         //bool statusCentralized;
         //CallCentralized.Post<bool>("User", "Update", out statusCentralized, model);
         //if (!statusCentralized)
         //{
         //    throw new Trinity.Common.ExceptionArgs(EnumMessage.NotConnectCentralized);
         //}
         //else
         //{
         Membership_Users dbUser;
         var localUserRepo = _localUnitOfWork.GetRepository <Membership_Users>();
         dbUser = localUserRepo.GetById(model.UserId);
         SetInfo(dbUser, model);
         localUserRepo.Update(dbUser);
         return(_localUnitOfWork.Save() > 0);
         //}
     }
     else
     {
         Membership_Users dbUser;
         var centralUserRepo = _centralizedUnitOfWork.GetRepository <Membership_Users>();
         dbUser = centralUserRepo.GetById(model.UserId);
         SetInfo(dbUser, model);
         centralUserRepo.Update(dbUser);
         return(_centralizedUnitOfWork.Save() > 0);
     }
 }
Exemplo n.º 6
0
        public MaybeEmpty <BE.User> Get(long userId)
        {
            var user = new BE.User()
            {
                Id = 1, Password = "******"
            };

            return(MaybeEmpty <BE.User> .Of(user));
        }
Exemplo n.º 7
0
        public MaybeEmpty <BE.SessionToken> GenerateToken(BE.User user)
        {
            var token        = GenerateToken(TokenSize, true);
            var sessionToken = new BE.SessionToken()
            {
                User = user, Token = token, Active = true
            };

            _storage.Save(sessionToken);
            return(MaybeEmpty <BE.SessionToken> .Of(sessionToken));
        }
Exemplo n.º 8
0
        private Membership_Users UpdateLocal(BE.User model, string userId)
        {
            Membership_Users dbUser;
            var localUserRepo = _localUnitOfWork.GetRepository <Membership_Users>();

            dbUser = localUserRepo.GetById(userId);
            SetInfo(dbUser, model);
            localUserRepo.Update(dbUser);
            _localUnitOfWork.Save();
            return(dbUser);
        }
Exemplo n.º 9
0
        private Membership_Users UpdateCentral(BE.User model, string userId)
        {
            Membership_Users dbUser;
            var centralUserRepo = _centralizedUnitOfWork.GetRepository <Membership_Users>();

            dbUser = centralUserRepo.GetById(userId);
            SetInfo(dbUser, model);
            centralUserRepo.Update(dbUser);
            _centralizedUnitOfWork.Save();
            return(dbUser);
        }
Exemplo n.º 10
0
        //public BE.User GetUserById(string userId)
        //{
        //    try
        //    {
        //        if (EnumAppConfig.IsLocal)
        //        {
        //            var user = (from mu in _localUnitOfWork.DataContext.Membership_Users
        //                        join mur in _localUnitOfWork.DataContext.Membership_UserRoles on mu.UserId equals mur.UserId
        //                        join mr in _localUnitOfWork.DataContext.Membership_Roles on mur.RoleId equals mr.Id
        //                        where mu.UserId == userId
        //                        select new Trinity.BE.User() { UserId = mu.UserId, Status = mu.Status, SmartCardId = mu.SmartCardId, RightThumbFingerprint = mu.RightThumbFingerprint, LeftThumbFingerprint = mu.LeftThumbFingerprint, Name = mu.Name, NRIC = mu.NRIC, Role = mr.Name, IsFirstAttempt = mu.IsFirstAttempt, AccessFailedCount = mu.AccessFailedCount, User_Photo1 = mu.User_Profiles.User_Photo1, User_Photo2 = mu.User_Profiles.User_Photo2 });
        //            if (user != null)
        //            {
        //                return user.FirstOrDefault();
        //            }
        //            else
        //            {
        //                bool centralizeStatus;
        //                var centralData = CallCentralized.Get<BE.User>(EnumAPIParam.User, "GetUserByUserId", out centralizeStatus, "userId=" + userId);
        //                if (centralizeStatus)
        //                {
        //                    return centralData;
        //                }
        //            }


        //        }
        //        else
        //        {
        //            var user = (from mu in _centralizedUnitOfWork.DataContext.Membership_Users
        //                        join mur in _centralizedUnitOfWork.DataContext.Membership_UserRoles on mu.UserId equals mur.UserId
        //                        join mr in _centralizedUnitOfWork.DataContext.Membership_Roles on mur.RoleId equals mr.Id
        //                        where mu.UserId == userId
        //                        select new Trinity.BE.User() { UserId = mu.UserId, Status = mu.Status, SmartCardId = mu.SmartCardId, RightThumbFingerprint = mu.RightThumbFingerprint, LeftThumbFingerprint = mu.LeftThumbFingerprint, Name = mu.Name, NRIC = mu.NRIC, Role = mr.Name, IsFirstAttempt = mu.IsFirstAttempt });
        //            return user.FirstOrDefault();
        //        }
        //        return null;
        //    }
        //    catch (Exception)
        //    {

        //        return null;
        //    }
        //}

        //public Trinity.BE.User GetSuperviseeByNRIC(string nric, bool isLocal)
        //{
        //    if (isLocal)
        //    {
        //        var user = (from mu in _localUnitOfWork.DataContext.Membership_Users
        //                    join mur in _localUnitOfWork.DataContext.Membership_UserRoles on mu.UserId equals mur.UserId
        //                    join mr in _localUnitOfWork.DataContext.Membership_Roles on mur.RoleId equals mr.Id
        //                    where mu.NRIC == nric
        //                    select new Trinity.BE.User() { UserId = mu.UserId, Status = mu.Status, SmartCardId = mu.SmartCardId, RightThumbFingerprint = mu.RightThumbFingerprint, LeftThumbFingerprint = mu.LeftThumbFingerprint, Name = mu.Name, NRIC = mu.NRIC, Role = mr.Name, IsFirstAttempt = mu.IsFirstAttempt });
        //        return user.FirstOrDefault();
        //    }
        //    else
        //    {
        //        var user = (from mu in _centralizedUnitOfWork.DataContext.Membership_Users
        //                    join mur in _centralizedUnitOfWork.DataContext.Membership_UserRoles on mu.UserId equals mur.UserId
        //                    join mr in _centralizedUnitOfWork.DataContext.Membership_Roles on mur.RoleId equals mr.Id
        //                    where mu.NRIC == nric
        //                    select new Trinity.BE.User() { UserId = mu.UserId, Status = mu.Status, SmartCardId = mu.SmartCardId, RightThumbFingerprint = mu.RightThumbFingerprint, LeftThumbFingerprint = mu.LeftThumbFingerprint, Name = mu.Name, NRIC = mu.NRIC, Role = mr.Name, IsFirstAttempt = mu.IsFirstAttempt });
        //        return user.FirstOrDefault();
        //    }
        //}
        public Response <bool> UpdateUser(BE.User model)
        {
            try
            {
                if (EnumAppConfig.IsLocal)
                {
                    UpdateCentral(model, model.UserId);
                    UpdateLocal(model, model.UserId);
                    return(new Response <bool>((int)EnumResponseStatuses.Success, EnumResponseMessage.Success, true));
                }
                else
                {
                    UpdateCentral(model, model.UserId);
                    return(new Response <bool>((int)EnumResponseStatuses.Success, EnumResponseMessage.Success, true));
                }
            }
            catch (Exception ex)
            {
                return(new Response <bool>((int)EnumResponseStatuses.ErrorSystem, EnumResponseMessage.ErrorSystem, false));
            }
        }
Exemplo n.º 11
0
        public BE.User Login_Centralized(string username, string password)
        {
            if (EnumAppConfig.IsLocal)
            {
                return(null);
            }

            //password = CreatePasswordHash(password);

            ApplicationUser applicationUser = ApplicationIdentityManager.GetUserManager().Find(username, password);

            if (applicationUser != null)
            {
                // get data
                BE.User returnValue = _centralizedUnitOfWork.DataContext.Membership_Users
                                      .Where(item => item.NRIC == applicationUser.NRIC)
                                      .Select(item => new Trinity.BE.User()
                {
                    UserId                = item.UserId,
                    Status                = item.Status,
                    SmartCardId           = item.SmartCardId,
                    RightThumbFingerprint =
                        item.RightThumbFingerprint,
                    LeftThumbFingerprint = item.LeftThumbFingerprint,
                    Name           = item.Name,
                    NRIC           = item.NRIC,
                    Role           = item.Membership_UserRoles.FirstOrDefault().Membership_Roles.Name,
                    IsFirstAttempt = item.IsFirstAttempt
                }).FirstOrDefault();

                // return value
                return(returnValue);
            }

            return(null);
        }
Exemplo n.º 12
0
 internal void Update(BE.User user)
 {
     return;
 }
Exemplo n.º 13
0
        public Trinity.BE.User GetUserBySmartCardId(string smartCardId)
        {
            try
            {
                // local request
                if (EnumAppConfig.IsLocal)
                {
                    // get from localdb
                    BE.User returnValue = _localUnitOfWork.DataContext.Membership_Users
                                          .Where(item => item.SmartCardId == smartCardId)
                                          .Select(item => new Trinity.BE.User()
                    {
                        UserId                = item.UserId,
                        Status                = item.Status,
                        SmartCardId           = item.SmartCardId,
                        RightThumbFingerprint =
                            item.RightThumbFingerprint,
                        LeftThumbFingerprint = item.LeftThumbFingerprint,
                        Name           = item.Name,
                        NRIC           = item.NRIC,
                        Role           = item.Membership_UserRoles.FirstOrDefault().Membership_Roles.Name,
                        User_Photo1    = item.User_Profiles.User_Photo1,
                        User_Photo2    = item.User_Profiles.User_Photo2,
                        IsFirstAttempt = item.IsFirstAttempt,
                        Expired_Date   = item.User_Profiles.Expired_Date
                    }).FirstOrDefault();


                    // if local null, get data from centralized - check bypass
                    if (returnValue == null && !EnumAppConfig.ByPassCentralizedDB)
                    {
                        bool centralizeStatus = false;
                        var  centralData      = CallCentralized.Get <BE.User>(EnumAPIParam.User, "GetUserBySmartCardId", out centralizeStatus, "smartCardId=" + smartCardId);
                        if (centralizeStatus)
                        {
                            returnValue = centralData;
                        }
                    }

                    // return value
                    return(returnValue);
                }
                else // centralized api request
                {
                    BE.User returnValue = _centralizedUnitOfWork.DataContext.Membership_Users
                                          .Where(item => item.SmartCardId == smartCardId)
                                          .Select(item => new Trinity.BE.User()
                    {
                        UserId                = item.UserId,
                        Status                = item.Status,
                        SmartCardId           = item.SmartCardId,
                        RightThumbFingerprint =
                            item.RightThumbFingerprint,
                        LeftThumbFingerprint = item.LeftThumbFingerprint,
                        Name           = item.Name,
                        NRIC           = item.NRIC,
                        Role           = item.Membership_UserRoles.FirstOrDefault().Membership_Roles.Name,
                        IsFirstAttempt = item.IsFirstAttempt,
                        Expired_Date   = item.User_Profiles.Expired_Date
                    }).FirstOrDefault();

                    // return value
                    return(returnValue);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 14
0
 internal static void Save(BE.User user)
 {
     //TODO: actually
 }
Exemplo n.º 15
0
        public Trinity.BE.User GetSuperviseeByNRIC(string nric)
        {
            if (EnumAppConfig.IsLocal)
            {
                // get Supervisee roleId
                string superviseeRoleId = _localUnitOfWork.DataContext.Membership_Roles.Where(item => item.Name == EnumUserRoles.Supervisee).FirstOrDefault()?.Id;
                if (string.IsNullOrEmpty(superviseeRoleId))
                {
                    return(null);
                }

                // get list user
                BE.User returnValue = _localUnitOfWork.DataContext.Membership_Users
                                      .Where(item => item.Membership_UserRoles.Any(role => role.RoleId == superviseeRoleId) && item.NRIC == nric)
                                      .Select(item => new Trinity.BE.User()
                {
                    UserId                = item.UserId,
                    Status                = item.Status,
                    SmartCardId           = item.SmartCardId,
                    RightThumbFingerprint =
                        item.RightThumbFingerprint,
                    LeftThumbFingerprint = item.LeftThumbFingerprint,
                    Name           = item.Name,
                    NRIC           = item.NRIC,
                    Role           = item.Membership_UserRoles.FirstOrDefault().Membership_Roles.Name,
                    IsFirstAttempt = item.IsFirstAttempt
                }).FirstOrDefault();

                if (returnValue == null)
                {
                    returnValue = CallCentralized.Get <Trinity.BE.User>("User", "GetSuperviseeByNRIC", "nric=" + nric);
                }

                // return value
                return(returnValue);
            }
            else
            {
                // get Supervisee roleId
                string superviseeRoleId = _centralizedUnitOfWork.DataContext.Membership_Roles.Where(item => item.Name == EnumUserRoles.Supervisee).FirstOrDefault()?.Id;
                if (string.IsNullOrEmpty(superviseeRoleId))
                {
                    return(null);
                }

                // get list user
                BE.User returnValue = _centralizedUnitOfWork.DataContext.Membership_Users
                                      .Where(item => item.Membership_UserRoles.Any(role => role.RoleId == superviseeRoleId) && item.NRIC == nric)
                                      .Select(item => new Trinity.BE.User()
                {
                    UserId                = item.UserId,
                    Status                = item.Status,
                    SmartCardId           = item.SmartCardId,
                    RightThumbFingerprint =
                        item.RightThumbFingerprint,
                    LeftThumbFingerprint = item.LeftThumbFingerprint,
                    Name           = item.Name,
                    NRIC           = item.NRIC,
                    Role           = item.Membership_UserRoles.FirstOrDefault().Membership_Roles.Name,
                    IsFirstAttempt = item.IsFirstAttempt
                }).FirstOrDefault();

                // return value
                return(returnValue);
            }
        }
Exemplo n.º 16
0
 public EvaluationUserControl1(BE.User currentUser)
 {
     InitializeComponent();
     this.DataContext = new EvaluationViewModel(currentUser);
 }
Exemplo n.º 17
0
 /// <summary>
 /// add user to data base
 /// </summary>
 /// <param name="user"></param>
 public void AddUser(BE.User user)
 {
     bl.addUser(user);
 }
Exemplo n.º 18
0
 /// <summary>
 /// add user to database
 /// </summary>
 /// <param name="user"></param>
 public void AddUserFunc(BE.User user)
 {
     modelRegister.AddUser(user);
 }
Exemplo n.º 19
0
 internal long Save(BE.User user)
 {
     return(_storage.Save(user));
 }
Exemplo n.º 20
0
 internal long Save(BE.User user)
 {
     return(0);
 }
Exemplo n.º 21
0
 internal void Update(BE.User user)
 {
     _storage.Update(user);
 }
Exemplo n.º 22
0
 internal void Delete(BE.User user)
 {
     _storage.Delete(user);
 }
Exemplo n.º 23
0
 internal void Delete(BE.User user)
 {
     return;
 }
Exemplo n.º 24
0
        public void Execute(object parameter)
        {
            try
            {
                //extract the parameter and insert to user
                var     values = (Object[])parameter;
                BE.User user   = new BE.User();
                user.Name = values[0].ToString();
                user.Id   = values[1].ToString();
                //all feild that are not necessary if there is a problem with them - put defult value
                try
                {
                    user.Phone = values[2].ToString();
                }
                catch (Exception ex)
                {
                    user.Phone = "";
                }
                try
                {
                    user.Email = values[6].ToString();
                }
                catch (Exception ex)
                {
                    user.Phone = "";
                }

                try
                {
                    user.familyStatus = (BE.status)Enum.Parse(typeof(BE.status), values[3].ToString());
                }
                catch (Exception ex)
                {
                    user.familyStatus = BE.status.Single;
                }
                try
                {
                    user.Height = double.Parse(values[4].ToString());
                }
                catch (Exception ex)
                {
                    user.Height = 0;
                }
                try
                {
                    user.Weight = double.Parse(values[5].ToString());
                }
                catch (Exception ex)
                {
                    user.Weight = 0;
                }
                try
                {
                    user.Date = DateTime.Parse(values[7].ToString());
                }
                catch (Exception ex)
                {
                    user.Date = DateTime.Now;
                }
                var PasswordBox = values[8] as PasswordBox;
                user.Password = PasswordBox.Password.ToString();
                rVm.AddUserFunc(user); //call function in vm that sdd this user
                MessageBox.Show("User Created successfully");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }