Ejemplo n.º 1
0
 public CreatePersonCommandHandler(HCMContext context, IMediator mediator, ICurrentUser currentUser)
 {
     _context      = context;
     _mediator     = mediator;
     _personCommon = new PersonCommon(_context);
     _currentUser  = currentUser;
 }
Ejemplo n.º 2
0
        public async Task <List <SearchedPersonModel> > Handle(SearchPersonQuery request, CancellationToken cancellationToken)
        {
            PersonCommon common = new PersonCommon(_context);
            List <SearchedPersonModel> result = new List <SearchedPersonModel>();

            result = await common.SearchPerson(request);

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <List <SearchedPersonRelative> > Handle(SavePersonRelatives request, CancellationToken cancellationToken)
        {
            List <SearchedPersonRelative> result = new List <SearchedPersonRelative>();

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

                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        using (_context)
                        {
                            Relative relative = new Relative()
                            {
                                RelationShipId  = request.RelationShipId,
                                FirstName       = request.FirstName,
                                LastName        = request.LastName,
                                FatherName      = request.FatherName,
                                GrandFatherName = request.GrandFatherName,
                                Profession      = request.Profession,
                                LocationId      = request.LocationId,
                                PersonId        = request.PersonId,
                                NidNo           = request.NidNo,
                                Address         = request.Address,
                                ContactInfo     = request.ContactInfo,
                                EmailAddress    = request.EmailAddress,
                                Village         = request.Village,
                                Remark          = request.Remark,

                                CreatedOn  = request.CreatedOn,
                                ModifiedBy = request.ModifiedBy,

                                ModifiedOn = request.ModifiedOn,
                                CreatedBy  = request.CreatedBy
                            };
                            _context.Relative.Add(relative);
                            await _context.SaveChangesAsync(CurrentUserId, cancellationToken);


                            PersonCommon common = new PersonCommon(_context);

                            // Return Saved Relative
                            result = await common.SearchPersonRelative(new Queries.SearchPersonRelativeQuery()
                            {
                                Id = relative.Id
                            }, cancellationToken);
                        }
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw new Exception();
                    }
                }
            }



            else
            {
                using (_context)
                {
                    Relative UpdateableRecord = await(from r in _context.Relative
                                                      where r.Id == request.Id
                                                      select r).FirstOrDefaultAsync(cancellationToken);



                    UpdateableRecord.FatherName      = request.FatherName;
                    UpdateableRecord.FirstName       = request.FirstName;
                    UpdateableRecord.LastName        = request.LastName;
                    UpdateableRecord.PersonId        = request.PersonId;
                    UpdateableRecord.GrandFatherName = request.GrandFatherName;
                    UpdateableRecord.RelationShipId  = request.RelationShipId;
                    UpdateableRecord.NidNo           = request.NidNo;
                    UpdateableRecord.Profession      = request.Profession;
                    UpdateableRecord.Address         = request.Address;
                    UpdateableRecord.ContactInfo     = request.ContactInfo;
                    UpdateableRecord.EmailAddress    = request.EmailAddress;
                    UpdateableRecord.Village         = request.Village;
                    UpdateableRecord.Remark          = request.Remark;
                    UpdateableRecord.ModifiedBy      = request.ModifiedBy;
                    UpdateableRecord.ModifiedOn      = request.ModifiedOn;

                    await _context.SaveChangesAsync(cancellationToken);

                    PersonCommon common = new PersonCommon(_context);
                    // Return Saved Relative
                    result = await common.SearchPersonRelative(new Queries.SearchPersonRelativeQuery()
                    {
                        Id = UpdateableRecord.Id
                    }, cancellationToken);
                }
            }


            return(result);
        }
Ejemplo n.º 4
0
        public async Task <List <SearchedPersonLanguage> > Handle(SavePersonLanguageCommand request, CancellationToken cancellationToken)
        {
            List <SearchedPersonLanguage> result = new List <SearchedPersonLanguage>();
            PersonCommon common = new PersonCommon(_context);

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

                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        using (_context)
                        {
                            PersonLanguage personLanguage = new PersonLanguage()
                            {
                                PersonId               = request.PersonId,
                                LanguageId             = request.LanguageId,
                                ReadingExpertise       = request.ReadingExpertise,
                                UnderstandingExpertise = request.UnderstandingExpertise,
                                WritingExpertise       = request.WritingExpertise,
                                SpeakingExpertise      = request.SpeakingExpertise,
                                ReferenceNo            = request.ReferenceNo,
                                CreatedOn              = request.CreatedOn,
                                CreatedBy              = request.CreatedBy
                            };
                            _context.PersonLanguage.Add(personLanguage);
                            await _context.SaveChangesAsync(CurrentUserId, cancellationToken);

                            result = await common.SearchPersonLanguages(new Queries.SearchPersonLanguageQuery()
                            {
                                Id = personLanguage.Id
                            }, cancellationToken);

                            transaction.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw new Exception();
                    }
                }
            }
            else
            {
                using (_context)
                {
                    PersonLanguage toUpdateRecord = await(from pl in _context.PersonLanguage
                                                          where pl.Id == request.Id
                                                          select pl).SingleOrDefaultAsync();

                    toUpdateRecord.LanguageId             = request.LanguageId;
                    toUpdateRecord.ReadingExpertise       = request.ReadingExpertise;
                    toUpdateRecord.UnderstandingExpertise = request.UnderstandingExpertise;
                    toUpdateRecord.WritingExpertise       = request.WritingExpertise;
                    toUpdateRecord.SpeakingExpertise      = request.SpeakingExpertise;



                    await _context.SaveChangesAsync(cancellationToken);

                    //result = await _context.PersonLanguage.Where(pl => pl.Id == toUpdateRecord.Id).ToListAsync(cancellationToken);

                    result = await common.SearchPersonLanguages(new Queries.SearchPersonLanguageQuery()
                    {
                        Id = toUpdateRecord.Id
                    }, cancellationToken);
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        public async Task <List <SearchedPersonRelative> > Handle(SearchPersonRelativeQuery request, CancellationToken cancellationToken)
        {
            PersonCommon common = new PersonCommon(_context);

            return(await common.SearchPersonRelative(request, cancellationToken));
        }