Esempio n. 1
0
        public void ChangeImage(int id, byte[] image)
        {
            IRepository <Mst_Profile> repo = _unitOfWork.GetRepository <Mst_Profile>();

            Mst_Profile profile = repo.GetQueryable(o => o.UserId == id).FirstOrDefault();

            string rootPath = AppDomain.CurrentDomain.BaseDirectory;

            File.WriteAllBytes(rootPath + @"\Content\UserImages\" + Helper.Username, image);
            profile.Photo = rootPath + @"\Content\UserImages\" + Helper.Username;
            repo.Update(profile);

            _unitOfWork.Execute();
        }
        public void UpdateUser(UserDetailViewModel model)
        {
            bool isChangeUsername = false;

            // Check username
            Mst_Credential cred = _unitOfWork.GetRepository<Mst_Credential>()
                .GetQueryable(o => o.Username == model.Username && o.UserId != model.UserId).FirstOrDefault();
            if (cred != null) throw new ArgumentException("Username already exists");

            // Update Credential
            IRepository<Mst_Credential> repoCredential = _unitOfWork.GetRepository<Mst_Credential>();
            Mst_Credential credential = repoCredential.GetQueryable(o => o.UserId == model.UserId).FirstOrDefault();
            if (credential != null)
            {
                if (credential.Username != model.Username)
                {
                    credential.Username = model.Username;
                    isChangeUsername = true;
                }
                credential.UserCode = model.UserCode;
                credential.Role = model.Role;
                credential.Status = model.Status;
                repoCredential.Update(credential);
            }

            // Update Profile
            IRepository<Mst_Profile> repoProfile = _unitOfWork.GetRepository<Mst_Profile>();
            Mst_Profile profile = repoProfile.GetQueryable(o => o.UserId == model.UserId).FirstOrDefault();
            if (profile != null)
            {
                profile.FirstName = model.FirstName;
                profile.LastName = model.LastName;
                profile.Position = model.Position;
                profile.Devision = model.Devision;
                profile.Status = model.Status;
                if (isChangeUsername) profile.Photo = string.Format("..{0}{1}.jpg", FILE_PATH, model.Username);
                repoProfile.Update(profile);
            }

            _unitOfWork.Execute();

            // Create default image
            if (isChangeUsername) CopyNoImageFile(model.Username);
        }
        public void CreateUser(UserDetailViewModel model)
        {
            // Check username
            Mst_Credential cred = _unitOfWork.GetRepository<Mst_Credential>().GetQueryable(o => o.Username == model.Username).FirstOrDefault();
            if (cred != null) throw new ArgumentException("Username already exists");

            // Insert Credential
            Mst_Credential credential = MappingUserDetailViewModelToCredential(model);
            _unitOfWork.GetRepository<Mst_Credential>().Insert(credential);
            _unitOfWork.Execute();

            // Insert Profile
            model.UserId = credential.UserId;
            Mst_Profile profile = MappingUserDetailViewModelToProfile(model);
            _unitOfWork.GetRepository<Mst_Profile>().Insert(profile);
            _unitOfWork.Execute();

            // Create default image
            CopyNoImageFile(model.Username);
        }
        public void UpdateUserStatus(int id, int status)
        {
            IRepository<Mst_Credential> repoCred = _unitOfWork.GetRepository<Mst_Credential>();
            IRepository<Mst_Profile> repoProfile = _unitOfWork.GetRepository<Mst_Profile>();

            Mst_Credential credential = repoCred.GetQueryable(o => o.UserId == id).FirstOrDefault();
            if (credential != null)
            {
                credential.Status = status;
                repoCred.Update(credential);

                Mst_Profile profile = repoProfile.GetQueryable(o => o.UserId == id).FirstOrDefault();
                if (profile != null)
                {
                    profile.Status = status;
                    repoProfile.Update(profile);
                }
            }

            _unitOfWork.Execute();
        }
Esempio n. 5
0
        public void UpdateEmployee(EmployeeDetailViewModel model)
        {
            // Update Profile
            IRepository <Mst_Profile> repoProfile = _unitOfWork.GetRepository <Mst_Profile>();
            Mst_Profile profile = repoProfile.GetQueryable(o => o.ProfileId == model.ProfileId).FirstOrDefault();

            if (profile != null)
            {
                //profile.FirstName = model.FirstName;
                //profile.LastName = model.LastName;
                profile.NickName = model.NickName;
                //profile.Position = model.Position;
                //profile.Devision = model.Devision;
                profile.Address   = model.Address;
                profile.Email     = model.Email;
                profile.Telephone = model.Telephone;
                //profile.Photo = model.Photo;
                repoProfile.Update(profile);
            }

            _unitOfWork.Execute();
        }