예제 #1
0
        public async Task <List <SearchedProcessTracks> > Handle(SaveProcessTracksCommand request, CancellationToken cancellationToken)
        {
            List <SearchedProcessTracks> result = new List <SearchedProcessTracks>();

            if (request.Id == null)
            {
                ProcessTracking PT = new ProcessTracking()
                {
                    RecordId         = request.RecordId,
                    ProcessId        = (Int16)request.ProcessId,
                    StatusId         = 5, // In Process
                    ModuleId         = request.ModuleId,
                    ReferedProcessId = 1,
                    CreatedOn        = DateTime.Now
                };
                _context.ProcessTracking.Add(PT);
                await _context.SaveChangesAsync(cancellationToken);
            }
            else
            {
                ProcessTracking track = await(from a in _context.ProcessTracking
                                              where a.Id == request.Id
                                              select a).SingleOrDefaultAsync();
                track.StatusId         = 6;
                track.ReferedProcessId = request.ReferedProcessId;
                ProcessTracking PT = new ProcessTracking()
                {
                    RecordId  = request.RecordId,
                    ProcessId = (Int16)request.ReferedProcessId,
                    StatusId  = 5,
                    Remarks   = request.Remarks,
                    ModuleId  = request.ModuleId,
                    CreatedOn = DateTime.Now
                };
                _context.ProcessTracking.Add(PT);
                await _context.SaveChangesAsync(cancellationToken);
            }
            result = await _mediator.Send(new SearchProcessTrackQuery()
            {
                RecordId = request.RecordId,
                ModuleId = request.ModuleId
            });

            return(result);
        }
예제 #2
0
        public async Task <List <SearchedPersonModel> > Handle(CreatePersonCommand request, CancellationToken cancellationToken)
        {
            List <SearchedPersonModel> result = new List <SearchedPersonModel>();

            // Save
            if (request.Id == null || request.Id == default(decimal))
            {
                int CurrentUserId = await _currentUser.GetUserId();

                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        #region BuildHrCode
                        StringBuilder PrefixBuilder = new StringBuilder(string.Empty);
                        StringBuilder HrCodeBuilder = new StringBuilder(string.Empty);

                        // Build Prefix
                        PrefixBuilder.Append(("00" + request.BirthLocationId.ToString()).Right(2));
                        PrefixBuilder.Append(("00" + Convert.ToDateTime(request.DateOfBirth).Month.ToString()).Right(2));
                        PrefixBuilder.Append(("0000" + Convert.ToDateTime(request.DateOfBirth).Year.ToString()).Right(4));
                        PrefixBuilder.Append(("00" + Convert.ToDateTime(request.CreatedOn).Day.ToString()).Right(2));
                        PrefixBuilder.Append(("00" + Convert.ToDateTime(request.CreatedOn).Month.ToString()).Right(2));
                        PrefixBuilder.Append(Convert.ToDateTime(request.CreatedOn).Year.ToString().Right(2));

                        //Build Suffix
                        //Get Current Suffix where its prefix is equal to PrefixBuilder.
                        int?Suffix;
                        int?CurrentSuffix = await _context.Person.Where(p => p.PreFix == PrefixBuilder.ToString()).MaxAsync(s => s.Suffix);

                        if (CurrentSuffix is null)
                        {
                            CurrentSuffix = 1;
                        }
                        Suffix = CurrentSuffix + 1;

                        // Build HR Code
                        HrCodeBuilder.Append(PrefixBuilder.ToString());
                        HrCodeBuilder.Append(("000" + Suffix.ToString()).Right(3));
                        #endregion BuildHrCode
                        #region SaveAndReturnResult
                        // Construct Person Object
                        Person person = new Person()
                        {
                            FirstName          = request.FirstName.Trim(),
                            FirstNameEng       = request.FirstNameEng.Trim(),
                            LastName           = request.LastName.Trim(),
                            FatherName         = request.FatherName,
                            FatherNameEng      = request.FatherNameEng,
                            GrandFatherName    = request.GrandFatherName,
                            GrandFatherNameEng = request.GrandFatherNameEng,
                            LastNameEng        = request.LastNameEng.Trim(),
                            PreFix             = PrefixBuilder.ToString(),
                            Suffix             = Suffix,
                            Hrcode             = HrCodeBuilder.ToString(),
                            DateOfBirth        = request.DateOfBirth,
                            BirthLocationId    = request.BirthLocationId,
                            GenderId           = request.GenderId,
                            MaritalStatusId    = request.MaritalStatusId,
                            EthnicityId        = request.EthnicityId,
                            ReligionId         = request.ReligionId,
                            Comments           = request.Comments,
                            StatusId           = request.StatusId,
                            Remark             = request.Remark,
                            BloodGroupId       = request.BloodGroupId,
                            ModifiedBy         = request.ModifiedBy,
                            CreatedBy          = request.CreatedBy,
                            CreatedOn          = request.CreatedOn,

                            Nid            = request.Nid,
                            PhotoPath      = request.PhotoPath,
                            DocumentTypeId = request.DocumentTypeId,
                            OrganizationId = request.OrganizationId
                        };
                        _context.Person.Add(person);
                        await _context.SaveChangesAsync(CurrentUserId, cancellationToken);

                        ProcessTracking PT = new ProcessTracking()
                        {
                            // CHANGE: Don't convert person.Id to integer, instead make the RecordId to include different types
                            RecordId         = Convert.ToInt32(person.Id),
                            ProcessId        = (Int16)request.ProcessID,
                            StatusId         = 5, // In Process
                            ModuleId         = request.ModuleID,
                            ReferedProcessId = 1,
                            CreatedOn        = DateTime.Now
                        };
                        _context.ProcessTracking.Add(PT);

                        await _context.SaveChangesAsync(CurrentUserId, cancellationToken);

                        result = await _personCommon.SearchPerson(new SearchPersonQuery()
                        {
                            Id = person.Id
                        });


                        #endregion SaveAndReturnResult

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw new Exception();
                    }
                }

                return(result);
            }
            // Update
            else
            {
                Person UpdateablePerson = (from p in _context.Person
                                           where p.Id == request.Id
                                           select p).First();

                UpdateablePerson.FirstName          = request.FirstName;
                UpdateablePerson.LastName           = request.LastName;
                UpdateablePerson.FatherName         = request.FatherName;
                UpdateablePerson.FatherNameEng      = request.FatherNameEng;
                UpdateablePerson.GrandFatherName    = request.GrandFatherName;
                UpdateablePerson.FirstNameEng       = request.FirstNameEng;
                UpdateablePerson.LastNameEng        = request.LastNameEng;
                UpdateablePerson.GrandFatherNameEng = request.GrandFatherNameEng;
                UpdateablePerson.BirthLocationId    = request.BirthLocationId;
                UpdateablePerson.GenderId           = request.GenderId;
                UpdateablePerson.MaritalStatusId    = request.MaritalStatusId;
                UpdateablePerson.EthnicityId        = request.EthnicityId;
                UpdateablePerson.ReligionId         = request.ReligionId;
                UpdateablePerson.Comments           = request.Comments;
                UpdateablePerson.BloodGroupId       = request.BloodGroupId;
                UpdateablePerson.Nid            = request.Nid;
                UpdateablePerson.PhotoPath      = request.PhotoPath;
                UpdateablePerson.DocumentTypeId = request.DocumentTypeId;
                UpdateablePerson.OrganizationId = request.OrganizationId;

                await _context.SaveChangesAsync();

                result = await _personCommon.SearchPerson(new SearchPersonQuery()
                {
                    Id = UpdateablePerson.Id
                });

                return(result);
            }
        }
예제 #3
0
        public bool AssignApplicationToEmployee(long applicationId)
        {
            try
            {
                using (var db = new ImportPermitEntities())
                {
                    //get the application that has been paid for
                    var application = db.Applications.Find(applicationId);

                    //make sure it is paid for
                    if (application.ApplicationStatusCode != (int)AppStatus.Submitted)
                    {
                        return(false);
                    }
                    const int appStage = (int)AppStage.Application;

                    //get the step with a sequence of one in application stage
                    var firstStep = db.Steps.Where(s => s.SequenceNumber == 1 && s.Process.ImportStageId == appStage).ToList();

                    if (firstStep.Any())
                    {
                        //get the group the step belong to
                        //var group = db.Groups.Find(firstStep[0].GroupId);

                        var groupId        = firstStep[0].GroupId;
                        var activityTypeId = firstStep[0].ActivityTypeId;
                        var stepId         = firstStep[0].Id;
                        //get the employees in that group
                        var emp = (from e in db.EmployeeDesks

                                   where e.GroupId.Equals(groupId) && e.ActivityTypeId.Equals(activityTypeId)
                                   orderby e.JobCount ascending
                                   select new EmployeeStepObject
                        {
                            EmployeeDeskId = e.Id,

                            JobCount = e.JobCount
                        }).ToList().First();


                        if (emp != null)
                        {
                            var track = new ProcessTracking();
                            track.ApplicationId = applicationId;
                            track.EmployeeId    = emp.EmployeeDeskId;
                            track.StepId        = stepId;
                            track.AssignedTime  = DateTime.Now;
                            track.StepCode      = 1;
                            track.StatusId      = (int)AppStatus.Processing;

                            db.ProcessTrackings.Add(track);

                            //update employee job count

                            var empId = emp.EmployeeDeskId;

                            var employeeDesk = db.EmployeeDesks.Find(empId);

                            employeeDesk.JobCount = employeeDesk.JobCount + 1;

                            employeeDesk.ApplicationCount = employeeDesk.ApplicationCount + 1;

                            db.EmployeeDesks.Attach(employeeDesk);
                            db.Entry(employeeDesk).State = EntityState.Modified;

                            //change the application status
                            application.ApplicationStatusCode = (int)AppStatus.Processing;
                            db.Entry(application).State       = EntityState.Modified;
                            db.SaveChanges();


                            db.Entry(employeeDesk).State = EntityState.Modified;
                            db.SaveChanges();

                            return(true);
                        }
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(false);
            }
        }