public async Task <Result <AddUpdatePersonContactResponse> > Handle(AddUpdatePersonContactCommand request, CancellationToken cancellationToken)
        {
            try
            {
                RegisterPersonService registerPersonService = new RegisterPersonService(_unitOfWork);
                PersonContact         personContact         = await registerPersonService.GetPersonContactByPersonId(request.PersonId);

                if (personContact != null)
                {
                    await registerPersonService.UpdatePersonContact(request.PersonId, request.PhysicalAddress,
                                                                    request.MobileNumber, request.EmailAddress, request.AlternativeNumber);
                }
                else
                {
                    personContact = await registerPersonService.addPersonContact(request.PersonId,
                                                                                 request.PhysicalAddress, request.MobileNumber, request.AlternativeNumber, request.EmailAddress,
                                                                                 request.UserId);
                }

                return(Result <AddUpdatePersonContactResponse> .Valid(new AddUpdatePersonContactResponse()
                {
                    PersonContactId = personContact.Id,
                    Message = "Person Contact Successful"
                }));
            }
            catch (Exception e)
            {
                return(Result <AddUpdatePersonContactResponse> .Invalid(e.Message));
            }
        }
Пример #2
0
        public async Task <Result <AddUpdatePersonContactResponse> > Handle(AddUpdatePersonContactCommand request, CancellationToken cancellationToken)
        {
            try
            {
                RegisterPersonService rs = new RegisterPersonService(_unitOfWork);
                if (request.PersonId > 0)
                {
                    PersonContact pc = new PersonContact();
                    pc = await rs.GetPersonContactByPersonId(request.PersonId);

                    if (pc != null)
                    {
                        pc.MobileNumber      = request.MobileNumber;
                        pc.AlternativeNumber = request.AlternativeNumber;
                        pc.EmailAddress      = request.EmailAddress;
                        pc.PersonId          = request.PersonId;

                        var personcontact = await rs.UpdatePersonContact(pc.PersonId, pc.MobileNumber, pc.AlternativeNumber, pc.Id);

                        if (personcontact != null)
                        {
                            res  = personcontact.Id;
                            msg += "Person Contact Updated Successfully";
                        }
                    }
                    else
                    {
                        var personcontact = await rs.addPersonContact(request.PersonId, request.PhysicalAddress, request.MobileNumber, request.AlternativeNumber, request.EmailAddress, request.UserId);

                        if (personcontact != null)
                        {
                            res  = personcontact.Id;
                            msg += "Person Contact Added Successfully";
                        }
                    }
                }
                else
                {
                    var personcontact = await rs.addPersonContact(request.PersonId, request.PhysicalAddress, request.MobileNumber, request.AlternativeNumber, request.EmailAddress, request.UserId);

                    if (personcontact != null)
                    {
                        res  = personcontact.Id;
                        msg += "Person Contact Added Successfully";
                    }
                }


                return(Result <AddUpdatePersonContactResponse> .Valid(new AddUpdatePersonContactResponse()
                {
                    PersonContactId = res,
                    Message = msg
                }));
            }
            catch (Exception e)
            {
                return(Result <AddUpdatePersonContactResponse> .Invalid(e.Message));
            }
        }
Пример #3
0
        public async Task <IActionResult> Post([FromBody] AddUpdatePersonContactCommand addUpdatePersonContactCommand)
        {
            var response = await _mediator.Send(addUpdatePersonContactCommand, Request.HttpContext.RequestAborted);

            if (response.IsValid)
            {
                return(Ok(response.Value));
            }
            return(BadRequest(response));
        }