コード例 #1
0
ファイル: StaffsService.cs プロジェクト: sanjuktasunar/WEB
        public string Insert(StaffsDto dto)
        {
            var    conn        = _baseInterface.GetConnection();
            var    transaction = conn.BeginTransaction();
            string message     = "";

            try
            {
                var photoStorage = new PhotoStorages();
                photoStorage.Photo         = null;
                photoStorage.PhotoLocation = null;
                int photoStorageId = _photoStorageRepository.Insert(photoStorage, transaction, conn);

                var user = dto.ToUserEntity();
                user.PhotoStorageId = photoStorageId;
                user.Password       = Web.Repositories.Utitlities.Security.GetMd5Sum(dto.Password);
                user.CreatedDate    = DateTime.Now;
                user.CreatedBy      = Convert.ToInt32(HttpContext.Current.Session["UserId"]);
                int userId = _usersRepository.Insert(user, transaction, conn);

                var staff = dto.ToEntity();
                staff.UserId = userId;
                int staffId = _staffsRepository.Insert(staff, transaction, conn);

                message = _messageClass.ShowSuccessMessage(staffId);
                transaction.Commit();
            }
            catch (SqlException ex)
            {
                message = _messageClass.ShowErrorMessage(string.Format("{0} ~ {1}", ex.Number.ToString(), ex.Message));
                transaction.Rollback();
            }
            return(message);
        }
コード例 #2
0
        public async Task <string> Update(StaffsDto dto)
        {
            if (!menu.ModifyAccess)
            {
                return(null);
            }

            return(await _staffsService.Update(dto));
        }
コード例 #3
0
        public string Insert(StaffsDto dto)
        {
            if (!menu.WriteAccess)
            {
                return(null);
            }

            return(_staffsService.Insert(dto));
        }
コード例 #4
0
        public async Task <ActionResult> AddStaff()
        {
            if (!menu.WriteAccess)
            {
                return(RedirectToAction("Logout", "Account"));
            }

            var obj = new StaffsDto();

            obj = await _staffsService.DropDownMethods(obj);

            return(View("AddModifyStaff", obj));
        }
コード例 #5
0
ファイル: StaffsService.cs プロジェクト: sanjuktasunar/WEB
        public async Task <StaffsDto> DropDownMethods(StaffsDto dto)
        {
            if (dto is null)
            {
                dto = new StaffsDto();
            }

            dto.Roles = await _administrationService.GetActiveRoleAsync();

            dto.Designations = await _administrationService.GetActiveDesignationAsync();

            dto.Departments = await _administrationService.GetActiveDepartmentAsync();

            dto.Genders = await _administrationService.GetActiveGenderAsync();

            dto.UserStatus = await _administrationService.GetActiveUserStatusAsync();

            return(dto);
        }
コード例 #6
0
ファイル: StaffsService.cs プロジェクト: sanjuktasunar/WEB
        public async Task <string> Update(StaffsDto dto)
        {
            SqlTransaction transaction;
            var            conn = _baseInterface.GetConnection();

            transaction = conn.BeginTransaction();
            string message = "";

            try
            {
                var staff = await _staffsRepository.GetStaffByIdAsync(dto.StaffId);

                if (staff == null)
                {
                    return(null);
                }
                var user = await _usersRepository.GetUserByIdAsync(staff.UserId);

                user.UserName      = dto.UserName;
                user.EmailAddress  = dto.EmailAddress;
                user.ContactNumber = dto.ContactNumber;
                user.UserStatusId  = dto.UserStatusId;
                user.UpdatedBy     = Convert.ToInt32(HttpContext.Current.Session["UserId"]);
                user.UpdatedDate   = DateTime.Now;
                _usersRepository.Update(user, transaction, conn);

                var staffEntity = dto.ToEntity();
                staffEntity.UserId = user.UserId;
                int staffId = _staffsRepository.Update(staffEntity, transaction, conn);

                message = _messageClass.ShowSuccessMessage(staffId);
                transaction.Commit();
            }
            catch (SqlException ex)
            {
                message = _messageClass.ShowErrorMessage(string.Format("{0} ~ {1}", ex.Number.ToString(), ex.Message));
                transaction.Rollback();
            }
            return(message);
        }
コード例 #7
0
        public static Users ToUserEntity(this StaffsDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            return(new Users
            {
                UserId = dto.UserId,
                UserTypeId = 2,
                PhotoStorageId = dto.PhotoStorageId,
                UserName = dto.UserName,
                Password = dto.Password,
                EmailAddress = dto.EmailAddress,
                ContactNumber = dto.ContactNumber,
                CreatedBy = dto.CreatedBy,
                CreatedDate = dto.CreatedDate,
                UpdatedBy = dto.UpdatedBy,
                UpdatedDate = dto.UpdatedDate,
                UserStatusId = dto.UserStatusId,
            });
        }
コード例 #8
0
        public static Staffs ToEntity(this StaffsDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            return(new Staffs
            {
                StaffId = dto.StaffId,
                UserId = dto.UserId,
                RoleId = dto.RoleId,
                DesignationId = dto.DesignationId,
                DepartmentId = dto.DepartmentId,
                StaffName = dto.StaffName,
                GenderId = dto.GenderId,
                TemporaryAddress = dto.TemporaryAddress,
                PermanentAddress = dto.PermanentAddress,
                CitizenshipNumber = dto.CitizenshipNumber,
                PanNumber = dto.PanNumber,
                BasicSalary = dto.BasicSalary,
            });
        }