public void Update(UpdatePersonnelHourlyShiftDto dto)
        {
            var personnelHourlyShift = _personnelHourlyShiftRepository.GetById(dto.Id);

            if (personnelHourlyShift != null)
            {
                foreach (var personnelId in dto.PersonnelIdList)
                {
                    personnelHourlyShift.Id            = dto.Id;
                    personnelHourlyShift.PersonnelId   = personnelId;
                    personnelHourlyShift.HourlyShiftId = dto.HourlyShiftId;
                    personnelHourlyShift.DateAssigned  = DateTime.Now;

                    _personnelHourlyShiftRepository.Update(personnelHourlyShift);
                }
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "PersonnelHourlyShift entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
        public void Update(UpdateHourlyShiftDto dto)
        {
            var hourlyShift = _shiftRepository.GetById(dto.Id);

            if (hourlyShift != null)
            {
                hourlyShift.Title = dto.Title;
                hourlyShift.HoursShouldWorkInDay = dto.HoursShouldWorkInDay.HasValue
                    ? (int?)dto.HoursShouldWorkInDay.Value.GetHoursInSeconds() : null;
                hourlyShift.HoursShouldWorkInWeek = dto.HoursShouldWorkInWeek.HasValue
                    ? (int?)dto.HoursShouldWorkInWeek.Value.GetHoursInSeconds() : null;
                hourlyShift.HoursShouldWorkInMonth = dto.HoursShouldWorkInMonth.HasValue
                    ? (int?)dto.HoursShouldWorkInMonth.Value.GetHoursInSeconds() : null;

                _shiftRepository.Update(hourlyShift);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "HourlyShift entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
Ejemplo n.º 3
0
        public void Update(UpdatePositionDto dto)
        {
            var position = _positionRepository.GetById(dto.Id);

            if (position != null)
            {
                position.WorkUnitId = dto.WorkUnitId;
                position.Title      = dto.Title;

                _positionRepository.Update(position);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "Position entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
        public void Update(UpdateRestrictedAccessTimeDto dto)
        {
            var restrictedAccessTime = _restrictedAccessTimeRepository.GetById(dto.Id);

            if (restrictedAccessTime != null)
            {
                restrictedAccessTime.Date     = dto.Date;
                restrictedAccessTime.FromTime = dto.FromTime;
                restrictedAccessTime.ToTime   = dto.ToTime;

                _restrictedAccessTimeRepository.Update(restrictedAccessTime);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "RestrictedAccessTime entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
Ejemplo n.º 5
0
        public void Update(UpdateDutyDto dto)
        {
            var duty = _dutyRepository.GetById(dto.Id);

            if (duty != null)
            {
                duty.Title           = dto.Title;
                duty.ActionLimitDays = dto.ActionLimitDays;

                _dutyRepository.Update(duty);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "Duty entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
Ejemplo n.º 6
0
        public void Update(UpdateEmployeementTypeDto dto)
        {
            var employeementType = _employeementTypeRepository.GetById(dto.Id);

            if (employeementType != null)
            {
                employeementType.Title = dto.Title;

                _employeementTypeRepository.Update(employeementType);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "EmployeementType entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
        public void Update(UpdateCalendarDateDto dto)
        {
            var calendarDate = _calendarDateRepository.GetById(dto.Id);

            if (calendarDate != null)
            {
                calendarDate.Title     = dto.Title;
                calendarDate.IsHoliday = dto.IsHoliday;

                _calendarDateRepository.Update(calendarDate);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "CalendarDate entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
Ejemplo n.º 8
0
        public void Update(UpdateWorkUnitDto dto)
        {
            var workUnit = _workUnitRepository.GetById(dto.Id);

            if (workUnit != null)
            {
                workUnit.Title = dto.Title;

                _workUnitRepository.Update(workUnit);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "WorkUnit entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
        public void Update(UpdateApprovalProcDto dto)
        {
            var approvalProc = _approvalProcRepository.GetById(dto.Id);

            if (approvalProc != null)
            {
                approvalProc.Title            = dto.Title;
                approvalProc.ParentId         = dto.ParentId;
                approvalProc.FirstPriorityId  = dto.FirstPriorityId;
                approvalProc.SecondPriorityId = dto.SecondPriorityId;
                approvalProc.ThirdPriorityId  = dto.ThirdPriorityId;
                approvalProc.ActiveState      = dto.ActiveState;

                _approvalProcRepository.Update(approvalProc);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "ApprovalProc entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
        public void Update(UpdateRestrictedDto dto)
        {
            var restrictedIP = _restrictedIPsRepository.GetById(dto.Id);

            if (restrictedIP != null)
            {
                restrictedIP.IP = dto.IP;

                _restrictedIPsRepository.Update(restrictedIP);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "RestrictedIP entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
Ejemplo n.º 11
0
        public void Update(UpdateGroupCategoryDto dto)
        {
            var groupCategory = _groupCategoryRepository.GetById(dto.Id);

            if (groupCategory != null)
            {
                groupCategory.Title = dto.Title;

                _groupCategoryRepository.Update(groupCategory);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "GroupCategory entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
Ejemplo n.º 12
0
        public CustomResult Update(UpdateWorkingHourDto dto)
        {
            var workingHour = _workingHourRepository.GetById(dto.Id);

            if (workingHour != null)
            {
                var result = CheckFilters(dto.FromTime, dto.ToTime, dto.MealTimeBreakFromTime
                                          , dto.MealTimeBreakToTime, dto.Break1FromTime, dto.Break1ToTime
                                          , dto.Break2FromTime, dto.Break2ToTime, dto.Break3FromTime, dto.Break3ToTime
                                          , dto.WorkingHourDuration);
                if (!result.IsValid)
                {
                    return(result);
                }

                workingHour.ShiftId               = dto.ShiftId;
                workingHour.Title                 = dto.Title;
                workingHour.FromTime              = dto.FromTime;
                workingHour.ToTime                = dto.ToTime;
                workingHour.WorkingHourDuration   = dto.WorkingHourDuration;
                workingHour.DailyDelay            = dto.DailyDelay.GetSecondsFromDuration();
                workingHour.MonthlyDelay          = dto.MonthlyDelay.GetSecondsFromDuration();
                workingHour.DailyRush             = dto.DailyRush.GetSecondsFromDuration();
                workingHour.MonthlyRush           = dto.MonthlyRush.GetSecondsFromDuration();
                workingHour.PriorExtraWorkTime    = dto.PriorExtraWorkTime.GetSecondsFromDuration();
                workingHour.LaterExtraWorkTime    = dto.LaterExtraWorkTime.GetSecondsFromDuration();
                workingHour.FloatingTime          = dto.FloatingTime.GetSecondsFromDuration();
                workingHour.MealTimeBreakFromTime = dto.MealTimeBreakFromTime;
                workingHour.MealTimeBreakToTime   = dto.MealTimeBreakToTime;
                workingHour.Break1FromTime        = dto.Break1FromTime;
                workingHour.Break1ToTime          = dto.Break1ToTime;
                workingHour.Break2FromTime        = dto.Break2FromTime;
                workingHour.Break2ToTime          = dto.Break2ToTime;
                workingHour.Break3FromTime        = dto.Break3FromTime;
                workingHour.Break3ToTime          = dto.Break3ToTime;

                _workingHourRepository.Update(workingHour);

                return(new CustomResult
                {
                    IsValid = true
                });
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "WorkingHour entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
Ejemplo n.º 13
0
        public CustomResult Update(UpdatePersonnelEntranceDto dto)
        {
            var personnelEntrance = _personnelEntranceRepository.GetById(dto.Id);

            if (personnelEntrance != null)
            {
                var exitDate = dto.ExitDate;

                if (personnelEntrance.Enter != dto.Enter ||
                    personnelEntrance.ExitDate != exitDate ||
                    personnelEntrance.Exit != dto.Exit)
                {
                    if (exitDate.HasValue &&
                        exitDate < personnelEntrance.EnterDate.Date)
                    {
                        return(new CustomResult
                        {
                            Message = "exit date cannot be less that enter date" +
                                      $"{personnelEntrance.EnterDate.ToShortDateString()}"
                        });
                    }

                    personnelEntrance.AutoEnter = personnelEntrance.Enter != dto.Enter
                        ? false : personnelEntrance.AutoEnter;
                    personnelEntrance.Enter    = dto.Enter;
                    personnelEntrance.ExitDate = exitDate;
                    personnelEntrance.AutoExit =
                        (personnelEntrance.Exit != dto.Exit || personnelEntrance.ExitDate != exitDate)
                        ? false : personnelEntrance.AutoExit;
                    personnelEntrance.Exit        = dto.Exit;
                    personnelEntrance.IsCompleted = dto.Exit.HasValue ? true : false;
                    personnelEntrance.IsEdited    = true;
                    personnelEntrance.EditDate    = DateTime.Now;

                    _personnelEntranceRepository.Update(personnelEntrance);
                }
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "PersonnelEntrance entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }

            return(new CustomResult
            {
                IsValid = true
            });
        }
        public CustomResult Update(UpdatePersonnelDismissalEntranceDto dto)
        {
            var personnelDismissalEntrance = _personnelDismissalEntranceRepository.GetById(dto.Id);

            if (personnelDismissalEntrance != null)
            {
                var endDate = dto.EndDate;

                if (personnelDismissalEntrance.Start != dto.Start ||
                    personnelDismissalEntrance.EndDate != endDate ||
                    personnelDismissalEntrance.End != dto.End)
                {
                    if (endDate.HasValue &&
                        endDate < personnelDismissalEntrance.StartDate.Date)
                    {
                        return(new CustomResult
                        {
                            Message = "end date cannot be less that start date" +
                                      $"{personnelDismissalEntrance.StartDate.ToShortDateString()}"
                        });
                    }

                    personnelDismissalEntrance.Start       = dto.Start;
                    personnelDismissalEntrance.EndDate     = endDate;
                    personnelDismissalEntrance.End         = dto.End;
                    personnelDismissalEntrance.IsCompleted = dto.End.HasValue;

                    _personnelDismissalEntranceRepository.Update(personnelDismissalEntrance);
                }
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "PersonnelDismissalEntrance entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }

            return(new CustomResult
            {
                IsValid = true
            });
        }
        public void Delete(int id, DeleteState deleteState)
        {
            var assignment = _personnelShiftAssignmentRepository.Get(q => q.Id == id
                                                                     , includeProperties: "PersonnelShift").SingleOrDefault();

            if (assignment != null)
            {
                //delete this assignment
                _personnelShiftAssignmentRepository.Delete(assignment, DeleteState.Permanent);

                //check if personnel shift has other assigments otherwise delete it
                var relativeAssignments = _personnelShiftAssignmentRepository
                                          .Get(q => q.PersonnelShiftId == assignment.PersonnelShiftId && q.Id != assignment.Id)
                                          .ToList();
                if (relativeAssignments.Count == 0)
                {
                    _personnelShiftRepository.Delete(assignment.PersonnelShiftId, DeleteState.Permanent);
                }
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError(ex, "Shift Assignment with Id: {0} should not be null" +
                                            ", delete operation failed.", assignment.Id);
                    throw;
                }
            }
        }
        public async Task <List <ShiftDDLDto> > GetPersonnelShifts(string username)
        {
            var user = await _authRepository.FindUserByUsernameAsync(username);

            if (user != null)
            {
                var shifts = _personnelShiftRepository
                             .Get(q => q.Personnel.Code == user.UserName, includeProperties: "Personnel,Shift")
                             .Select(x => x.Shift).Distinct().ToList();
                return(Mapper.Map <List <ShiftDDLDto> >(shifts));
            }
            try
            {
                throw new LogicalException();
            }
            catch (LogicalException ex)
            {
                _logger.LogLogicalError(ex, "corresponding personnel user with username: {0}" +
                                        "does not exist!", username);
                throw;
            }
        }
Ejemplo n.º 17
0
        public async Task <string> Create(CreateMessageDto dto, string senderUsername)
        {
            string receiverId = "";

            var sender = await _authRepository.FindUserByUsernameAsync(senderUsername);

            if (sender != null)
            {
                switch (dto.MessageType)
                {
                case MessageType.Normal:
                    var normalMessage = new Message
                    {
                        SenderId    = sender.Id,
                        ReceiverId  = dto.ReceiverId,
                        Date        = DateTime.Now,
                        Title       = dto.Title,
                        Content     = dto.Content,
                        MessageType = MessageType.Normal
                    };
                    _messageRepository.Insert(normalMessage);
                    receiverId = normalMessage.ReceiverId;
                    break;

                case MessageType.Request:
                    if (dto.Request != null)
                    {
                        var requestMessage = new RequestMessage
                        {
                            SenderId             = sender.Id,
                            ReceiverId           = dto.ReceiverId,
                            Date                 = DateTime.Now,
                            Title                = dto.Title,
                            Content              = dto.Content,
                            MessageType          = MessageType.Request,
                            RequestId            = dto.Request.RequestId,
                            RequestType          = dto.Request.RequestType,
                            ParentApprovalProcId = dto.Request.ParentApprovalProcId,
                            RequestAction        = dto.Request.RequestAction
                        };
                        _requestMessageRepository.Insert(requestMessage);
                        receiverId = requestMessage.ReceiverId;
                    }
                    else
                    {
                        MessageDetailsError(dto.MessageType, "create");
                    }
                    break;

                default:
                    break;
                }

                return(receiverId);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError(ex, "Sender user with username: {0} is not available!"
                                            , senderUsername);
                    throw;
                }
            }
        }
Ejemplo n.º 18
0
        public async Task <CustomResult <string> > Update(UpdatePersonnelDutyDto dto)
        {
            var personnelDuty = _personnelDutyRepository.GetById(dto.Id);

            if (personnelDuty != null)
            {
                dto.PersonnelId = personnelDuty.PersonnelId;
                var personnel = _personnelRepository.GetById(dto.PersonnelId);
                if (personnel == null)
                {
                    return(new CustomResult <string>
                    {
                        Message = "person is not available"
                    });
                }

                var user = await _authService.FindUserByUsernameAsync(personnel.Code);

                if (user == null)
                {
                    return(new CustomResult <string>
                    {
                        Message = "user for person not found"
                    });
                }

                if (AlreadyRequested(personnel.Id, dto.DailyDuty, dto.HourlyDuty, personnelDuty.Id))
                {
                    return(new CustomResult <string>
                    {
                        Message = "cannot add multiple duties in the time period"
                    });
                }

                if (personnelDuty.RequestAction == RequestAction.Unknown)
                {
                    DateTime from = DateTime.Now;
                    DateTime to   = DateTime.Now;
                    switch (dto.DutyDuration)
                    {
                    case RequestDuration.Daily:
                        if (personnelDuty.DutyDuration == dto.DutyDuration)     //update the same type
                        {
                            var dailyDuty = personnelDuty as PersonnelDailyDuty;
                            dailyDuty.PersonnelId        = dto.PersonnelId;
                            dailyDuty.DutyId             = dto.DutyId;
                            dailyDuty.SubmittedDate      = DateTime.Now;
                            dailyDuty.DutyDuration       = dto.DutyDuration;
                            dailyDuty.RequestDescription = dto.RequestDescription;
                            dailyDuty.FromDate           = dto.DailyDuty.FromDate;
                            dailyDuty.ToDate             = dto.DailyDuty.ToDate;

                            from = dailyDuty.FromDate;
                            to   = dailyDuty.ToDate;
                        }
                        else     //update entity type -> remove and insert again
                        {
                            try
                            {
                                await DeleteAndInsertAgain(dto);
                            }
                            catch (TransactionAbortedException ex)
                            {
                                _logger.LogRunTimeError(ex, ex.Message
                                                        + " Either update or delete operation failed.");
                                throw;
                            }
                            catch (Exception ex)
                            {
                                _logger.LogRunTimeError(ex, ex.Message);
                                throw;
                            }
                        }
                        break;

                    case RequestDuration.Hourly:
                        if (personnelDuty.DutyDuration == dto.DutyDuration)     //update the same type
                        {
                            var hourlyDuty = personnelDuty as PersonnelHourlyDuty;
                            hourlyDuty.PersonnelId        = dto.PersonnelId;
                            hourlyDuty.DutyId             = dto.DutyId;
                            hourlyDuty.SubmittedDate      = DateTime.Now;
                            hourlyDuty.DutyDuration       = dto.DutyDuration;
                            hourlyDuty.RequestDescription = dto.RequestDescription;
                            hourlyDuty.Date     = dto.HourlyDuty.Date;
                            hourlyDuty.FromTime = dto.HourlyDuty.FromTime;
                            hourlyDuty.ToTime   = dto.HourlyDuty.ToTime;

                            from = hourlyDuty.Date.Add(hourlyDuty.FromTime);
                            to   = hourlyDuty.Date.Add(hourlyDuty.ToTime);
                        }
                        else     //update entity type -> remove and insert again
                        {
                            try
                            {
                                await DeleteAndInsertAgain(dto);
                            }
                            catch (TransactionAbortedException ex)
                            {
                                _logger.LogRunTimeError(ex, ex.Message
                                                        + " Either update or delete operation failed.");
                                throw;
                            }
                            catch (Exception ex)
                            {
                                _logger.LogRunTimeError(ex, ex.Message);
                                throw;
                            }
                        }
                        break;

                    default:
                        break;
                    }

                    //Send Request Message to Approval Proc
                    //remove prev
                    _messageService.RemoveRequest(RequestType.Duty, personnelDuty.Id);
                    //insert new
                    var notificationReceiverId = await _requestMessageHandlerService
                                                 .HandleDutyRequest(personnelDuty.Id, personnelDuty.DutyDuration
                                                                    , from, to, user.Username);

                    if (notificationReceiverId == null)
                    {
                        return(new CustomResult <string>
                        {
                            Message = "approval procedure not found"
                        });
                    }

                    return(new CustomResult <string>
                    {
                        IsValid = true,
                        ReturnId = notificationReceiverId
                    });
                }
                else
                {
                    string requestAction = personnelDuty.RequestAction == RequestAction.Accept
                        ? "confirmed" : personnelDuty.RequestAction == RequestAction.PartialAccept
                        ? "waiting for confirmation" : "rejected";
                    return(new CustomResult <string>
                    {
                        IsValid = false,
                        Message = "cannot update the duty info, status: "
                                  + requestAction
                    });
                }
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "PersonnelDuty entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
Ejemplo n.º 19
0
        public CustomResult Update(UpdatePersonnelDto dto)
        {
            var personnel = _personnelRepository.GetById(dto.Id);

            if (personnel != null)
            {
                #region Update Personnel Info
                if (PersonnelCodeExistsInDB(dto.Code, personnel.Id))
                {
                    return(new CustomResult
                    {
                        IsValid = false,
                        Message = "person code is not unique"
                    });
                }
                if (NationalCodeExistsInDB(dto.NationalCode, personnel.Id))
                {
                    return(new CustomResult
                    {
                        IsValid = false,
                        Message = "national code is not unique"
                    });
                }
                personnel.Code                        = dto.Code;
                personnel.Name                        = dto.Name;
                personnel.LastName                    = dto.LastName;
                personnel.FathersName                 = dto.FathersName;
                personnel.NationalCode                = dto.NationalCode;
                personnel.BirthCertificateCode        = dto.BirthCertificateCode;
                personnel.PlaceOfBirth                = dto.PlaceOfBirth;
                personnel.State                       = dto.State;
                personnel.City                        = dto.City;
                personnel.PostalCode                  = dto.PostalCode;
                personnel.BirthDate                   = dto.BirthDate;
                personnel.Email                       = dto.Email;
                personnel.Mobile                      = dto.Mobile;
                personnel.Phone                       = dto.Phone;
                personnel.Address                     = dto.Address;
                personnel.Education                   = dto.Education;
                personnel.MilitaryServiceStatus       = dto.MilitaryServiceStatus;
                personnel.Gender                      = dto.Gender;
                personnel.MaritalStatus               = dto.MaritalStatus;
                personnel.GroupCategoryId             = dto.GroupCategoryId;
                personnel.EmployeementTypeId          = dto.EmployeementTypeId;
                personnel.PositionId                  = dto.PositionId;
                personnel.InsuranceRecordDuration     = dto.InsuranceRecordDuration;
                personnel.NoneInsuranceRecordDuration = dto.NoneInsuranceRecordDuration;
                personnel.BankAccountNumber           = dto.BankAccountNumber;
                personnel.DateOfEmployeement          = dto.DateOfEmployeement;
                personnel.FirstDateOfWork             = dto.FirstDateOfWork;
                personnel.LastDateOfWork              = dto.LastDateOfWork;
                personnel.LeavingWorkCause            = dto.LeavingWorkCause;
                personnel.ActiveState                 = dto.ActiveState;

                _personnelRepository.Update(personnel);
                #endregion

                #region Update Approvals
                _personnelApprovalProcService.CreateOrUpdate(new PersonnelApprovalProcDto
                {
                    Id = dto.Id,
                    DismissalApprovalProcId = dto.DismissalApprovalProcId,
                    DutyApprovalProcId      = dto.DutyApprovalProcId,
                    ShiftReplacementProcId  = dto.ShiftReplacementProcId
                });

                _dismissalApprovalService.Update(dto.DismissalApprovals, personnel.Id);
                _dutyApprovalService.Update(dto.DutyApprovals, personnel.Id);
                #endregion

                return(new CustomResult
                {
                    IsValid = true
                });
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "Personnel entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
Ejemplo n.º 20
0
        public async Task <PersonnelProfileDto> Get(string username)
        {
            var profileInfo = new PersonnelProfileDto();

            var connectedUser = await _authRepository.FindUserByUsernameAsync(username);

            if (connectedUser == null)
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError(ex, "personnel with code: {0}, " +
                                            "corresponding user is not available!", username);
                    throw;
                }
            }

            var personnel = _personnelRepository.Get(q => q.Code == username).SingleOrDefault();

            if (personnel != null)
            {
                profileInfo.Id        = personnel.Id;
                profileInfo.Name      = personnel.Name;
                profileInfo.LastName  = personnel.LastName;
                profileInfo.Mobile    = personnel.Mobile;
                profileInfo.IsPresent = personnel.IsPresent;

                //approval procs
                var personnelApprovalProc = _personnelApprovalProcRepository
                                            .Get(q => q.Id == personnel.Id).ToList();
                if (personnelApprovalProc != null)
                {
                    //dismissal proc
                    foreach (var item in personnelApprovalProc)
                    {
                        var dismissalApprovalProc = _approvalProcRepository
                                                    .Get(q => q.Id == item.DismissalApprovalProcId
                                                         , includeProperties: "ParentProc").ToList();
                        profileInfo.DismissalApprovalProcDto
                            = Mapper.Map <List <ApprovalProcDtoForProfile> >(dismissalApprovalProc);
                    }
                    //duty proc
                    foreach (var item in personnelApprovalProc)
                    {
                        var dutyApprovalProc = _approvalProcRepository
                                               .Get(q => q.Id == item.DutyApprovalProcId
                                                    , includeProperties: "ParentProc").ToList();
                        profileInfo.DutyApprovalProcDto
                            = Mapper.Map <List <ApprovalProcDtoForProfile> >(dutyApprovalProc);
                    }
                    //shift replacement proc
                    foreach (var item in personnelApprovalProc)
                    {
                        var shiftReplacementApprovalProc = _approvalProcRepository
                                                           .Get(q => q.Id == item.ShiftReplacementProcId
                                                                , includeProperties: "ParentProc").ToList();
                        profileInfo.ShiftReplacementApprovalProcDto
                            = Mapper.Map <List <ApprovalProcDtoForProfile> >(shiftReplacementApprovalProc);
                    }
                }
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError(ex, "Personnel with Code: {0}, is not available!"
                                            , username);
                    throw;
                }
            }

            return(profileInfo);
        }
Ejemplo n.º 21
0
        public async Task <CustomResult <string> > Update(UpdatePersonnelShiftReplacementDto dto)
        {
            var personnelShiftReplacement = _personnelShiftReplacementRepository.GetById(dto.Id);

            if (personnelShiftReplacement != null)
            {
                dto.PersonnelId = personnelShiftReplacement.PersonnelId;

                #region check if both personnel are available and have the same work unit
                var personnel = _personnelRepository.Get(q => q.Id == dto.PersonnelId
                                                         , includeProperties: "Position").SingleOrDefault();
                if (personnel == null)
                {
                    return(new CustomResult <string>
                    {
                        Message = "person info is not available"
                    });
                }
                var replacedPersonnel = _personnelRepository.Get(q => q.Id == dto.ReplacedPersonnelId
                                                                 , includeProperties: "Position").SingleOrDefault();
                if (replacedPersonnel == null)
                {
                    return(new CustomResult <string>
                    {
                        Message = "replaced person info is not available"
                    });
                }
                if (personnel.Position.WorkUnitId != replacedPersonnel.Position.WorkUnitId)
                {
                    return(new CustomResult <string>
                    {
                        Message = "work unit for both personnel should be the same"
                    });
                }
                var user = await _authService.FindUserByUsernameAsync(personnel.Code);

                #endregion

                var replacementDate = dto.ReplacementDate;

                if (AlreadyRequested(personnel.Id, replacementDate, personnelShiftReplacement.Id))
                {
                    return(new CustomResult <string>
                    {
                        Message = "cannot add multiple replacement in the same day"
                    });
                }

                #region check if replacement date is valid for any of the selected personnel
                var assignmentAvailable = _personnelShiftService.IsAssignmentAvailable(dto.ShiftId, replacementDate);
                if (!assignmentAvailable)
                {
                    return(new CustomResult <string>
                    {
                        Message = "there is no shift for the personnel in the requested date"
                    });
                }
                #endregion

                //ok
                if (personnelShiftReplacement.RequestAction == RequestAction.Unknown)
                {
                    personnelShiftReplacement.PersonnelId           = dto.PersonnelId;
                    personnelShiftReplacement.ReplacedPersonnelId   = dto.ReplacedPersonnelId;
                    personnelShiftReplacement.WorkingHourId         = dto.WorkingHourId;
                    personnelShiftReplacement.ReplacedWorkingHourId = dto.ReplacedWorkingHourId;
                    personnelShiftReplacement.ReplacementDate       = replacementDate;

                    _personnelShiftReplacementRepository.Update(personnelShiftReplacement);

                    //Send Request Message to Approval Proc
                    //remove prev
                    _messageService.RemoveRequest(RequestType.ShiftReplacement, personnelShiftReplacement.Id);
                    //insert new
                    var notificationReceiverId = await _requestMessageHandlerService
                                                 .HandleShiftReplacementRequest(personnelShiftReplacement.Id, user.Username);

                    if (notificationReceiverId == null)
                    {
                        return(new CustomResult <string>
                        {
                            Message = "shift replacement procedure not found"
                        });
                    }

                    return(new CustomResult <string>
                    {
                        IsValid = true,
                        ReturnId = notificationReceiverId
                    });
                }
                else
                {
                    string requestAction = personnelShiftReplacement.RequestAction == RequestAction.Accept
                        ? "confirmed" : personnelShiftReplacement.RequestAction == RequestAction.PartialAccept
                        ? "waiting for confirmation" : "rejected";
                    return(new CustomResult <string>
                    {
                        IsValid = false,
                        Message = "cannot update the shift replacement info, status:"
                                  + requestAction
                    });
                }
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "PersonnelShiftReplacement entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }