public async Task <IActionResult> Create(FuturesViewModel futuresViewModel)
        {
            if (ModelState.IsValid)
            {
                futuresViewModel.Id = Guid.NewGuid();
                var client = _clientServices.ClientExistByDni(futuresViewModel.Client.Dni);
                if (futuresViewModel.RefeerCode != null)
                {
                    var refeer = await _clientServices.GetClient(futuresViewModel.RefeerCode);

                    futuresViewModel.Refeer = refeer.Id;
                }
                if (!client)
                {
                    await _clientServices.CreateClient(futuresViewModel.Client);
                }
                else
                {
                    await _clientServices.UpdateClient(futuresViewModel.Client);
                }

                if (futuresViewModel.FixRent)
                {
                    futuresViewModel.ParticipationId = null;
                }

                if (!NoLimitclient(futuresViewModel.ContractNumber))
                {
                    futuresViewModel.FinishDate = futuresViewModel.StartDate.AddMonths(6);
                }
                else
                {
                    futuresViewModel.FinishDate = futuresViewModel.StartDate.AddYears(99);
                }

                await _futuresServices.CreateFuture(futuresViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(Problem(ModelState.IsValid.ToString(), null, 400));
            }
        }
Beispiel #2
0
        public async Task <ClientViewModel> CreateClient(ClientViewModel client)
        {
            ClientEntity  clientDetail = Mapper.Map <ClientEntity>(client);
            AddressEntity Address      = await _clientServices.GetAddress(client.AddressID ?? 0);

            if (Address == null)
            {
                ProcessResult(false, HttpStatusCode.BadRequest, "Endereço inválido!");
            }
            clientDetail.Address = Address;

            //clientDetail.Address.City = await _clientServices.GetCity(client.CityID ?? 0);
            //clientDetail.Address.City.State = await _clientServices.GetState(client.StateID ?? 0);
            //clientDetail.Address.City.State.Country = await _clientServices.GetCountry(client.CountryID ?? 0);

            ClientEntity clientResult = await _clientServices.CreateClient(clientDetail);

            ProcessResult <ClientEntity>(clientResult);
            return(Mapper.Map <ClientViewModel>(clientResult));
        }
 public IActionResult CreateClient(Client client)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (client.IdClient == 0)
             {
                 _clientServices.CreateClient(client);
                 //_clientServices.UpdateClientPayment(client);
             }
             else
             {
                 _clientServices.UpdateClient(client);
             }
             return(Json(new
             {
                 isValid = true,
                 html = Helper
                        .RenderRazorViewToString(this, "_ViewListClients", _clientServices.GetClients())
             }));
         }
         return(Json(new
         {
             isValid = false,
             html = Helper
                    .RenderRazorViewToString(this, "CreateClient", client)
         }));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(Json(new
         {
             isValid = false,
             html = Helper
                    .RenderRazorViewToString(this, "_ViewListClients", _clientServices.GetClients())
         }));
     }
 }
        public IActionResult CreateClient(Client client)
        {
            var newClient = _clientServices.CreateClient(client);

            return(CreatedAtRoute("GetClient", new { newClient.Id }, newClient));
        }