Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }