Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PostFincas(Fincas fincas)
        {
            //fincas.IngresoFinca = DateTime.Now.ToUniversalTime();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            fincas.ImagePath = "la cargo";

            //if (fincas.ImageArray != null && fincas.ImageArray.Length > 0)
            //{
            //    var stream = new MemoryStream(fincas.ImageArray);
            //    var guid = Guid.NewGuid().ToString();
            //    var file = $"{guid}.jpg";
            //    var folder = "~/Content/Fincas";
            //    var fullPath = $"{folder}/{file}";
            //    var response = FilesHelper.UploadPhoto(stream, folder, file);

            //    if (response)
            //    {
            //        fincas.ImagePath = fullPath;
            //    }
            //}

            db.Fincas.Add(fincas);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = fincas.FincaId }, fincas));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditFinca(Fincas Finca)
        {
            if (_dataContext.Fincas.Any(x => x.Codigo == Finca.Codigo))
            {
                var finca = _dataContext.Fincas.First(x => x.Codigo == Finca.Codigo);
                finca.FincaName = Finca.FincaName;
                try
                {
                    await _dataContext.SaveChangesAsync();

                    return(Ok(new { Data = new
                                    {
                                        finca.ID,
                                        finca.Codigo,
                                        finca.FincaName
                                    }, Success = true }));
                }
                catch (Exception ex)
                {
                    return(BadRequest(new { Data = ex.ToString(), Success = false }));
                }
            }
            else
            {
                return(BadRequest(new { Data = "La finca con codigo " + Finca.Codigo + " no se encuentra en la base de datos.", Success = false }));
            }
        }
Ejemplo n.º 3
0
 public FincasEditViewModel(Fincas fincaP)
 {
     this.finca              = fincaP;
     this.apiService         = new ApiService();
     this.IsEnabled          = true;
     this.finca.IngresoFinca = finca.IngresoFinca;
     this.imageSource        = finca.ImageFullPath;
 }
Ejemplo n.º 4
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Fincas fincas = await db.Fincas.FindAsync(id);

            db.Fincas.Remove(fincas);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public async Task <IHttpActionResult> GetFincas(int id)
        {
            Fincas fincas = await db.Fincas.FindAsync(id);

            if (fincas == null)
            {
                return(NotFound());
            }

            return(Ok(fincas));
        }
Ejemplo n.º 6
0
 private FincasView ToView(Fincas finca)
 {
     return(new FincasView
     {
         CiudadFinca = finca.CiudadFinca,
         EstadoFinca = finca.EstadoFinca,
         HabilitadaFinca = finca.HabilitadaFinca,
         ImagePath = finca.ImagePath,
         IngresoFinca = finca.IngresoFinca,
         NombreFinca = finca.NombreFinca,
         FincaId = finca.FincaId,
         PaisFinca = finca.PaisFinca,
     });
 }
Ejemplo n.º 7
0
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Fincas fincas = await db.Fincas.FindAsync(id);

            if (fincas == null)
            {
                return(HttpNotFound());
            }
            return(View(fincas));
        }
Ejemplo n.º 8
0
        public async Task <IHttpActionResult> DeleteFincas(int id)
        {
            Fincas fincas = await db.Fincas.FindAsync(id);

            if (fincas == null)
            {
                return(NotFound());
            }

            db.Fincas.Remove(fincas);
            await db.SaveChangesAsync();

            return(Ok(fincas));
        }
Ejemplo n.º 9
0
        public async Task <Fincas> Create(Fincas Finca)
        {
            if (!this.ExistFinca(Finca.Codigo))
            {
                _dataContext.Fincas.Add(Finca);
            }
            else
            {
                return(_dataContext.Fincas.FirstOrDefault(x => x.Codigo == Finca.Codigo));
            }
            await _dataContext.SaveChangesAsync();

            return(Finca);
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Fincas fincas = await db.Fincas.FindAsync(id);

            if (fincas == null)
            {
                return(HttpNotFound());
            }
            var fincaview = this.ToView(fincas);

            return(View(fincaview));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> CreateFinca(Fincas Finca)
        {
            List <Fincas> ListFinca = new List <Fincas>();

            try
            {
                Fincas F = await Create(Finca);

                _dataContext.Fincas.AddRange(ListFinca);
                return(Ok(new { Data = F, Success = true }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { Data = ex.ToString(), Success = false }));
            }
        }
Ejemplo n.º 12
0
        public async Task <IHttpActionResult> PutFincas(int id, Fincas fincas)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != fincas.FincaId)
            {
                return(BadRequest());
            }

            if (fincas.ImageArray != null && fincas.ImageArray.Length > 0)
            {
                var stream   = new MemoryStream(fincas.ImageArray);
                var guid     = Guid.NewGuid().ToString();
                var file     = $"{guid}.jpg";
                var folder   = "~/Content/Fincas";
                var fullPath = $"{folder}/{file}";
                var response = FilesHelper.UploadPhoto(stream, folder, file);

                if (response)
                {
                    fincas.ImagePath = fullPath;
                }
            }

            db.Entry(fincas).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FincasExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(fincas));
        }
Ejemplo n.º 13
0
        private async void Save()
        {
            if (String.IsNullOrEmpty(this.NombreFinca))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.NameError
                                                                , Languages.Accept);

                return;
            }

            if (String.IsNullOrEmpty(this.PaisFinca))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.CoutryError
                                                                , Languages.Accept);

                return;
            }

            if (String.IsNullOrEmpty(this.EstadoFinca))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.StateError
                                                                , Languages.Accept);

                return;
            }

            if (String.IsNullOrEmpty(this.CiudadFinca))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.CityError
                                                                , Languages.Accept);

                return;
            }

            this.IsRunning = true;
            this.IsEnabled = false;

            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept);

                return;
            }

            byte[] imageArray = null;
            if (this.file != null)
            {
                imageArray = FilesHelper.ReadFully(this.file.GetStream());
            }

            var finca = new Fincas
            {
                CiudadFinca     = this.CiudadFinca,
                EstadoFinca     = this.EstadoFinca,
                HabilitadaFinca = this.HabilitadaFinca,
                NombreFinca     = this.NombreFinca,
                PaisFinca       = this.PaisFinca,
                IngresoFinca    = this.IngresoFinca,
                ImageArray      = imageArray,
            };

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlFincasController"].ToString();
            var response   = await this.apiService.Post(url, prefix, controller, finca, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    response.Message,
                    Languages.Accept);

                return;
            }

            var newFinca        = (Fincas)response.Result;
            var fincasViewModel = FincasViewModel.GetInstance();

            fincasViewModel.myFincas.Add(newFinca);
            fincasViewModel.RefreshList();

            this.IsRunning = false;
            this.IsEnabled = true;
            await App.Navigator.PopAsync();
        }
Ejemplo n.º 14
0
        public async Task <string> CreateMasivo(List <CreatePomas> Pomas)
        {
            ExportadorController exportadorController = new ExportadorController(_dataContext);
            PuertoController     puertoController     = new PuertoController(_dataContext);
            BuqueController      buqueController      = new BuqueController(_dataContext);
            DestinoController    destinoController    = new DestinoController(_dataContext);
            FrutasController     frutasController     = new FrutasController(_dataContext);
            FincaController      fincaController      = new FincaController(_dataContext);
            PaletController      paletController      = new PaletController(_dataContext);
            List <Vehiculos>     ListPoma             = new List <Vehiculos>();

            foreach (var Poma in Pomas)
            {
                try
                {
                    Vehiculos Vehiculo = new Vehiculos();
                    Vehiculos V        = new Vehiculos();
                    V.Placa  = Poma.Placa;
                    Vehiculo = await this.Create(V);

                    Fincas Finca = new Fincas();
                    Fincas F     = new Fincas();
                    F.Codigo    = Poma.Finca.Codigo;
                    F.FincaName = Poma.Finca.FincaName;
                    Finca       = await fincaController.Create(F);


                    Puertos Puerto = new Puertos();
                    Puertos PU     = new Puertos();
                    PU.Codigo     = Poma.Puerto.Codigo;
                    PU.PuertoName = Poma.Puerto.PuertoName;
                    Puerto        = await puertoController.Create(PU);

                    Destinos Destino = new Destinos();
                    Destinos D       = new Destinos();
                    D.Codigo      = Poma.Destino.Codigo;
                    D.DestinoName = Poma.Destino.DestinoName;
                    Destino       = await destinoController.Create(D);

                    Buques Buque = new Buques();
                    Buques B     = new Buques();
                    B.Codigo    = Poma.Buque.Codigo;
                    B.BuqueName = Poma.Buque.BuqueName;
                    Buque       = await buqueController.Create(B);

                    Exportadores Exportador = new Exportadores();
                    Exportadores E          = new Exportadores();
                    E.Codigo         = Poma.Exportador.Codigo;
                    E.ExportadorName = Poma.Exportador.ExportadorName;
                    Exportador       = await exportadorController.Create(E);

                    TransportGuide TransportGuide = new TransportGuide();
                    TransportGuide.Vehiculo        = Vehiculo;
                    TransportGuide.Numero          = Poma.Numero;
                    TransportGuide.Estado          = (int)EstadosPoma.NoChequeado;
                    TransportGuide.FechaRegistro   = DateTime.UtcNow;
                    TransportGuide.Recibido        = false;
                    TransportGuide.LlegadaCamion   = Poma.LlegadaCamion.ToUniversalTime();
                    TransportGuide.SalidaFinca     = Poma.SalidaFinca.ToUniversalTime();
                    TransportGuide.Estimado        = Poma.Estimado.ToUniversalTime();
                    TransportGuide.LlegadaTerminal = null;
                    TransportGuide.Finca           = Finca;
                    TransportGuide.Puerto          = Puerto;
                    TransportGuide.Buque           = Buque;
                    TransportGuide.Destino         = Destino;
                    TransportGuide.Exportador      = Exportador;

                    bool           EditTG = false;
                    TransportGuide valTG  = this.ExistTransportGuide(Poma.Numero);
                    if (valTG == null)
                    {
                        _dataContext.TransportGuides.Add(TransportGuide);
                        await _dataContext.SaveChangesAsync();
                    }
                    else
                    {
                        var currentDate = DateTime.UtcNow.ToLocalTime();
                        var StartDate   = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 3, 0, 0);
                        var EndDate     = StartDate.AddDays(1);
                        EndDate = new DateTime(EndDate.Year, EndDate.Month, EndDate.Day, 2, 59, 0);
                        if (currentDate < StartDate)
                        {
                            StartDate = StartDate.AddDays(-1);
                            EndDate   = EndDate.AddDays(-1);
                        }
                        if ((valTG.FechaRegistro >= StartDate && valTG.FechaRegistro <= EndDate) && valTG.Estado == 0)
                        {
                            EditTG = true;
                        }
                        else
                        {
                            return("La poma ya existe");
                        }
                    }

                    foreach (var detail in Poma.DetailPoma)
                    {
                        Frutas Fruta = new Frutas();
                        Frutas FR    = new Frutas();
                        FR.Codigo    = detail.Frutas.Codigo;
                        FR.FrutaName = detail.Frutas.FrutaName;
                        Fruta        = await frutasController.Create(FR);

                        DetailTransportGuide valDTG   = null;
                        DetailTransportGuide DetailTG = new DetailTransportGuide();
                        DetailTG.Fruta = Fruta;
                        if (EditTG)
                        {
                            valDTG = this.ExistDetailTransportGuide(valTG.ID, Fruta.ID);
                            if (valDTG == null)
                            {
                                DetailTG.TransportGuide = valTG;
                                _dataContext.DetailTransportGuide.Add(DetailTG);
                                await _dataContext.SaveChangesAsync();
                            }
                        }
                        else
                        {
                            DetailTG.TransportGuide = TransportGuide;
                            _dataContext.DetailTransportGuide.Add(DetailTG);
                            await _dataContext.SaveChangesAsync();
                        }

                        foreach (var palet in detail.Palets)
                        {
                            Pallets Palet = new Pallets();
                            Palet.CodigoPalet       = palet.CodigoPalet;
                            Palet.UsuarioLectura    = "";
                            Palet.LecturaPalet      = DateTime.UtcNow;
                            Palet.UsuarioInspeccion = "";
                            Palet.InspeccionPalet   = DateTime.UtcNow;
                            Palet.CaraPalet         = palet.CaraPalet;
                            Palet.NumeroCajas       = palet.NumeroCajas;
                            Palet.Carga             = palet.Carga;
                            Palet.Tipo     = palet.Tipo;
                            Palet.Perfilar = false;
                            if (EditTG)
                            {
                                if (valDTG == null)
                                {
                                    Palet.DetailTransportGuide = DetailTG;
                                }
                                else
                                {
                                    Palet.DetailTransportGuide = valDTG;
                                }
                            }
                            else
                            {
                                Palet.DetailTransportGuide = DetailTG;
                            }
                            _dataContext.Palets.Add(Palet);
                        }
                    }
                }
                catch (Exception ex)
                {
                    continue;
                }
            }

            await _dataContext.SaveChangesAsync();

            try
            {
                await _NotificationHubContext.Clients.All.BroadcastMessage(Get());
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return("Ejecutado correctamente");
        }