public async Task <ClientResponseModel> CreateClient(ClientRequestModel clientRequestModel)
        {
            var client = new Clients
            {
                Name    = clientRequestModel.Name,
                Email   = clientRequestModel.Email,
                Phones  = clientRequestModel.Phones,
                Address = clientRequestModel.Address,
                AddedBy = clientRequestModel.AddedBy,
                AddedOn = clientRequestModel.AddedOn,
            };
            var createdClient = await _clientsRepository.AddAsync(client);

            var response = new ClientResponseModel
            {
                Id      = createdClient.Id,
                Name    = createdClient.Name,
                Email   = createdClient.Email,
                Phones  = createdClient.Phones,
                Address = createdClient.Address,
                AddedBy = createdClient.AddedBy,
                AddedOn = createdClient.AddedOn,
            };

            return(response);
        }
        public async Task <ClientResponseModel> UpdateClient(ClientUpdateRequestModel clientUpdateRequestModel, int id)
        {
            var dbClient = await _clientsRepository.GetByIdAsync(id);

            if (dbClient == null)
            {
                throw new Exception("No Client Exist");
            }
            var client = new Clients
            {
                Id      = dbClient.Id,
                Name    = clientUpdateRequestModel.Name == null ? dbClient.Name : clientUpdateRequestModel.Name,
                Email   = clientUpdateRequestModel.Email == null ? dbClient.Email : clientUpdateRequestModel.Email,
                Address = clientUpdateRequestModel.Address == null? dbClient.Address:clientUpdateRequestModel.Address,
                Phones  = clientUpdateRequestModel.Phones == null ? dbClient.Phones : clientUpdateRequestModel.Phones,
                AddedBy = clientUpdateRequestModel.AddedBy == null ? dbClient.AddedBy : clientUpdateRequestModel.AddedBy,
                AddedOn = dbClient.AddedOn,
            };
            var updatedClient = await _clientsRepository.UpdateAsync(client);

            var response = new ClientResponseModel
            {
                Id      = updatedClient.Id,
                Name    = updatedClient.Name,
                Email   = updatedClient.Email,
                Address = updatedClient.Address,
                Phones  = updatedClient.Phones,
                AddedBy = updatedClient.AddedBy,
                AddedOn = updatedClient.AddedOn,
            };

            return(response);
        }
Example #3
0
        public async Task <ClientResponseModel> GetClientById(int id)
        {
            var client = await _clientsRepository.GetByIdAsync(id);

            var response = new ClientResponseModel
            {
                Id      = client.Id,
                Name    = client.Name,
                Email   = client.Email,
                Phones  = client.Phones,
                AddedBy = client.AddedBy,
                AddedOn = client.AddedOn,
            };

            return(response);
        }
        /// <summary>
        /// Çalışana göre maaş bilgisini getirir
        /// </summary>
        public ClientResponseModel GetCalculatedSalary(int id)
        {
            var employee = _salaryRepo.GetEmployeeById(id);
            var service  = _calculator.GetCalculatorService(employee.SalaryType);
            var salary   = service.Calculate(employee);

            var result = new ClientResponseModel
            {
                IdentityNumber = employee.IdentityNumber,
                Firstname      = employee.Firstname,
                Lastname       = employee.Lastname,
                Salary         = salary
            };

            return(result);
        }
Example #5
0
        public async Task GivenTheClientIsRegistered(string name, string lastName)
        {
            var clientRequest = new ClientRequestModel
            {
                Name     = name,
                LastName = lastName
            };

            var response = await _client.PostAsJsonAsync("api/clients", clientRequest);

            response.StatusCode.Should().Be(HttpStatusCode.Created);
            var registeredClient = JsonConvert.DeserializeObject <ClientResponseModel>(await response.Content.ReadAsStringAsync());

            registeredClient.Id.Should().Be(1);
            registeredClient.Name.Should().Be(name);
            registeredClient.Lastname.Should().Be(lastName);

            _registeredClient = registeredClient;
        }
Example #6
0
 public IHttpActionResult Post([FromBody] Client client)
 {
     if (client.Name != null && client.Surname != null && client.Address != null)
     {
         string           path = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "RestfulTestfulFiles");
         SQLiteConnection db   = new SQLiteConnection(System.IO.Path.Combine(path, "RestfulTestfulDatabase.db"));
         client.TokenNumber = 1;
         if (!POEChecker.AlreadyIsInDatabase(client))
         {
             if (db.Insert(client) == 1)
             {
                 ClientResponseModel clientResponseModel = new ClientResponseModel(db.Table <Client>().Last(c => c.Name.Equals(client.Name) && c.Surname.Equals(client.Surname) && c.PhoneNumber.Equals(client.PhoneNumber) && c.Address.Equals(client.Address)), this.Url);
                 return(Ok <ClientResponseModel>(clientResponseModel));
             }
             return(InternalServerError(new Exception("Couldn't insert row into database")));
         }
         return(BadRequest("Object already is in database!"));
     }
     return(BadRequest("Client name, surname and address can't be null"));
 }
Example #7
0
        public async Task <IActionResult> Get(Guid?id)
        {
            var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim);

            var serviceModel = new GetClientServiceModel
            {
                Id             = id,
                Language       = CultureInfo.CurrentCulture.Name,
                OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value)
            };

            var validator = new GetClientModelValidator();

            var validationResult = await validator.ValidateAsync(serviceModel);

            if (validationResult.IsValid)
            {
                var client = await this.clientsService.GetAsync(serviceModel);

                if (client != null)
                {
                    var response = new ClientResponseModel
                    {
                        Id    = client.Id,
                        Email = client.Email,
                        Name  = client.Name,
                        CommunicationLanguage = client.CommunicationLanguage,
                        LastModifiedDate      = client.LastModifiedDate,
                        CreatedDate           = client.CreatedDate
                    };

                    return(this.StatusCode((int)HttpStatusCode.OK, response));
                }
                else
                {
                    return(this.StatusCode((int)HttpStatusCode.NotFound));
                }
            }

            throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity);
        }
        public List <ClientResponseModel> GetCalculatedSalaries()
        {
            var employees = _salaryRepo.GetEmployees();
            var result    = new List <ClientResponseModel>();

            foreach (var employeesGroup in employees.GroupBy(g => g.SalaryType))
            {
                var service = _calculator.GetCalculatorService(employeesGroup.Key);
                foreach (var employee in employeesGroup)
                {
                    var salary = service.Calculate(employee);

                    var model = new ClientResponseModel
                    {
                        IdentityNumber = employee.IdentityNumber,
                        Firstname      = employee.Firstname,
                        Lastname       = employee.Lastname,
                        Salary         = salary
                    };
                    result.Add(model);
                }
            }
            return(result);
        }
        public async Task <IActionResult> InsertAsync([FromBody] ClientRequestModel data)
        {
            JsonResult          result;
            ClientResponseModel response = new ClientResponseModel();

            Klijent newClient = new Klijent {
                BrojRacuna = long.Parse(data.BrojRacuna), AdresaISediste = data.AdresaISediste, ImeIPrezimeKlijenta = data.ImeIPrezimeKlijenta, PIB = long.Parse(data.PIB)
            };

            bool insertedClient = await _clientFacade.InsertAsync(newClient);

            if (!insertedClient)
            {
                response.Message = "Insert failed!";
                result           = new JsonResult(response);

                return(BadRequest(result));
            }

            response.Message = "Client inserted successfully!";
            result           = new JsonResult(response);

            return(result);
        }