Exemple #1
0
        public async Task <ActionResult <AddressDTO> > AddAddressAsync([FromBody] Address address)
        {
            int created = await _genericRepository.AddTAsync(address);

            if (created == 0)
            {
                var logData = new
                {
                    Address      = address,
                    Action       = ControllerContext.ActionDescriptor.DisplayName,
                    Verb         = HttpContext.Request.Method,
                    EndpointPath = HttpContext.Request.Path.Value,
                    User         = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value
                };
                _logger.LogInformation("No Address was created for the address {address}. Data: {@logData}", address, logData);

                return(NotFound("No Address was created"));
            }

            var newAddress = await _genericRepository.GetOneByAsync(ad =>
                                                                    ad.Client_Id == address.Client_Id &&
                                                                    ad.StreetNumber == address.StreetNumber &&
                                                                    ad.City == address.City);

            AddressDTO addressDTO = _mapper.Map <AddressDTO>(newAddress);

            return(Created("", addressDTO));
        }
        public async Task <ActionResult <BillableActivityDTO> > AddBillableActivityAsync([FromBody] BillableActivity billableActivity)
        {
            int created = await _genericRepository.AddTAsync(billableActivity);

            if (created == 0)
            {
                var logData = new
                {
                    NewBillableActivity = billableActivity,
                    Action       = ControllerContext.ActionDescriptor.DisplayName,
                    Verb         = HttpContext.Request.Method,
                    EndpointPath = HttpContext.Request.Path.Value,
                    User         = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value
                };
                _logger.LogInformation("No BillableActivity was created for {billableActivity}. Data: {@logData}", billableActivity, logData);

                return(NotFound("No Billable Activity was created"));
            }

            var newBillableActivity = await _genericRepository.GetOneByAsync(ba =>
                                                                             ba.Title == billableActivity.Title &&
                                                                             ba.Employee_Id == billableActivity.Employee_Id &&
                                                                             ba.LegalCase_Id == billableActivity.LegalCase_Id);

            BillableActivityDTO billableActivityDTO = _mapper.Map <BillableActivityDTO>(newBillableActivity);

            return(Created("", billableActivityDTO));
        }
Exemple #3
0
        public async Task <ActionResult <LegalCaseDTO> > AddLegalCaseAsync([FromBody] LegalCase legalCase)
        {
            int created = await _genericRepository.AddTAsync(legalCase);

            if (created == 0)
            {
                var logData = new
                {
                    LegalCase    = legalCase,
                    Action       = ControllerContext.ActionDescriptor.DisplayName,
                    Verb         = HttpContext.Request.Method,
                    EndpointPath = HttpContext.Request.Path.Value,
                    User         = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value
                };
                _logger.LogInformation("No LegalCase was created for Legalcase {@legalCase}. Data: {@logData}", legalCase, logData);

                return(NotFound("No Legal Case was created"));
            }

            var newLegalCase = await _genericRepository.GetOneByAsync(lc =>
                                                                      lc.Client_Id == legalCase.Client_Id &&
                                                                      lc.Title == legalCase.Title);

            LegalCaseDTO legalCaseDTO = _mapper.Map <LegalCaseDTO>(newLegalCase);

            return(Created("", legalCaseDTO));
        }
Exemple #4
0
        public async Task <ActionResult <EmployeeTypeDTO> > AddEmployeeType([FromBody] EmployeeType employeeType)
        {
            var addResult = await _genericRepository.AddTAsync(employeeType);

            if (addResult == 0)
            {
                var logData = new
                {
                    EmployeeType = employeeType,
                    Action       = ControllerContext.ActionDescriptor.DisplayName,
                    Verb         = HttpContext.Request.Method,
                    EndpointPath = HttpContext.Request.Path.Value,
                    User         = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value
                };
                _logger.LogInformation("No EmployeeType was created for the employeeType {@employeeType}. Data: {@logData}", employeeType, logData);

                return(NotFound("No EmployeeType was created"));
            }

            var newEmployeeType = await _genericRepository.GetOneByAsync(et => et.Description == employeeType.Description);

            var employeeTypeDTO = _mapper.Map <EmployeeTypeDTO>(newEmployeeType);

            return(Created("", employeeTypeDTO));
        }
Exemple #5
0
        public async Task <ActionResult <ClientDTO> > AddClientAsync([FromBody] Client client)
        {
            int created = await _genericRepository.AddTAsync(client);

            if (created == 0)
            {
                var logData = new
                {
                    Client       = client,
                    Action       = ControllerContext.ActionDescriptor.DisplayName,
                    Verb         = HttpContext.Request.Method,
                    EndpointPath = HttpContext.Request.Path.Value,
                    User         = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value
                };
                _logger.LogInformation("No Client was created for Client {@client}. Data: {@logData}", client, logData);

                return(NotFound("No Client was created"));
            }

            var newClient = await _genericRepository.GetOneByAsync(cl =>
                                                                   cl.Name == client.Name &&
                                                                   cl.Description == client.Description &&
                                                                   cl.Website == client.Website);

            ClientDTO clientDTO = _mapper.Map <ClientDTO>(newClient);

            return(Created("", clientDTO));
        }
Exemple #6
0
        public async Task <ActionResult <ContactDTO> > AddContactAsync([FromBody] Contact contact)
        {
            int created = await _genericRepository.AddTAsync(contact);

            if (created == 0)
            {
                var logData = new
                {
                    Contact      = contact,
                    Action       = ControllerContext.ActionDescriptor.DisplayName,
                    Verb         = HttpContext.Request.Method,
                    EndpointPath = HttpContext.Request.Path.Value,
                    User         = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value
                };
                _logger.LogInformation("No Contact was created for Contact {@contact}. Data: {@logData}", contact, logData);

                return(NotFound("No Contact was created"));
            }

            _logger.LogInformation("Contact was created for Contact {@contact}.", contact);

            var newContact = await _genericRepository.GetOneByAsync(co =>
                                                                    co.Client_Id == contact.Client_Id &&
                                                                    co.Name == contact.Name &&
                                                                    co.Position == contact.Position);

            ContactDTO contactDTO = _mapper.Map <ContactDTO>(newContact);

            return(Created("", contactDTO));
        }
        public async Task <ActionResult <ContactInfoDTO> > AddNewContactAsync([FromBody] ContactInfo newContact)
        {
            if (newContact == null)
            {
                return(NotFound("Input object cannot be null"));
            }
            newContact.Id = Guid.NewGuid().ToString();
            int created = await _genericRepository.AddTAsync(newContact);

            if (created == 0)
            {
                return(NotFound("No New Contact created"));
            }

            var newRecord = await _genericRepository.GetOneByAsync(t => t.Id == newContact.Id);

            ContactInfoDTO contactInfoDTO = _mapper.Map <ContactInfoDTO>(newRecord);

            return(Created("New Contact Created", contactInfoDTO));
        }