Пример #1
0
        public BodegaDto AddBodega(BodegaDto bodega)
        {
            Bodega b = _bodega.Create <Bodega>(DtoABodega(bodega));

            bodega.Id = b.Id;
            _notificacionService.NotificacionIngresado(b.Unidades, b);
            _logService.LogInventario(String.Format(StringEnum.GetStringValue(MensajeNotificaciones.Ingreso), bodega.Unidades, bodega.Botella.Descripcion));
            return(bodega);
        }
Пример #2
0
 private static Bodega CrearEntidad(BodegaDto dto)
 {
     return(new Bodega
     {
         Id = dto.Id,
         Nombre = dto.Nombre,
         Descripcion = dto.Descripcion,
         Ubicacion = dto.Ubicacion,
         CapacidadMaxima = dto.CapacidadMaxima
     });
 }
Пример #3
0
 public static Bodega Convertir(BodegaDto dto)
 {
     if (dto != null)
     {
         return(CrearEntidad(dto));
     }
     else
     {
         return(null);
     }
 }
Пример #4
0
        public ActionResult Agregar(BodegaDto bodega)
        {
            if (ModelState.IsValid)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(urlApi);
                    var responseTask = client.GetAsync(String.Format("Bodega/{0}", bodega.IdBotella));
                    responseTask.Wait();
                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsStringAsync();
                        readTask.Wait();

                        BodegaDto bod = JsonConvert.DeserializeObject <BodegaDto>(readTask.Result);
                        if (bod != null)
                        {
                            ModelState.AddModelError(string.Empty, StringEnum.GetStringValue(MensajeError.ExisteBodega));
                            ViewBag.ModalAgregar = true;
                            BodegaViewModel b = GetBodegaViewModel();
                            return(View("Index", b));
                        }
                    }
                    var myContent   = JsonConvert.SerializeObject(bodega);
                    var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
                    var byteContent = new ByteArrayContent(buffer);
                    byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    responseTask = client.PostAsync("Bodega", byteContent);
                    responseTask.Wait();

                    result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsStringAsync();
                        readTask.Wait();
                        bodega = JsonConvert.DeserializeObject <BodegaDto>(readTask.Result);
                    }
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                BodegaViewModel b = GetBodegaViewModel();
                ViewBag.ModalAgregar = true;
                return(View("Index", b));
            }
        }
Пример #5
0
 public IHttpActionResult Add(BodegaDto bodega)
 {
     try
     {
         return(Ok(_service.AddBodega(bodega)));;
     }
     catch (DbEntityValidationException efEx)
     {
         _logs.LogDbEntityValidationException(efEx);
     }
     catch (Exception ex)
     {
         _logs.LogException(ex);
     }
     return(Content(HttpStatusCode.NotFound, StringEnum.GetStringValue(MensajeError.NoRecuperado)));
 }
Пример #6
0
        private Bodega DtoABodega(BodegaDto b)
        {
            if (b == null)
            {
                return(null);
            }
            Bodega bodega = (new Bodega()
            {
                Id = b.Id,
                IdBotella = b.IdBotella,
                Unidades = b.Unidades,
                NotificadoCaducidad = b.NotificadoCaducidad
            });

            if (b.Botella != null)
            {
                bodega.Botella = DtoABotella(b.Botella);
            }
            return(bodega);
        }
Пример #7
0
        AddBodegaReturnCorrectBodega()
        {
            //Arrange
            Bodega bodega = new Bodega()
            {
                NotificadoCaducidad = It.IsAny <bool>(),
                Unidades            = It.IsAny <int>(),
                Botella             = new Botella()
                {
                    Id          = 4,
                    Descripcion = "Botella 4",
                    Añada       = It.IsAny <int>(),
                    Caducidad   = It.IsAny <DateTime>(),
                    Disponible  = true,
                    IdVino      = It.IsAny <int>(),
                    Vino        = new Vino()
                    {
                        Id           = It.IsAny <int>(),
                        Nombre       = It.IsAny <string>(),
                        Variedad     = It.IsAny <string>(),
                        Crianza      = It.IsAny <string>(),
                        Denominacion = It.IsAny <string>(),
                        Color        = It.IsAny <string>(),
                        Baja         = false,
                        Capacidad    = It.IsAny <decimal>()
                    }
                }
            };

            BodegaDto bodegadto = new BodegaDto()
            {
                NotificadoCaducidad = It.IsAny <bool>(),
                Unidades            = 25,
                Botella             = new BotellaDto()
                {
                    Id          = 4,
                    Descripcion = "Botella 4",
                    Añada       = It.IsAny <int>(),
                    Caducidad   = It.IsAny <DateTime>(),
                    Disponible  = true,
                    IdVino      = It.IsAny <int>(),
                    Vino        = new VinoDto()
                    {
                        Id           = It.IsAny <int>(),
                        Nombre       = It.IsAny <string>(),
                        Variedad     = It.IsAny <string>(),
                        Crianza      = It.IsAny <string>(),
                        Denominacion = It.IsAny <string>(),
                        Color        = It.IsAny <string>(),
                        Baja         = false,
                        Capacidad    = It.IsAny <decimal>()
                    }
                }
            };

            _bodegaRepository.Setup(x => x.Create(It.IsAny <Bodega>())).Returns(bodega);

            //Act
            var result = _service.AddBodega(bodegadto);

            //Assert
            Assert.AreEqual(result.Unidades, 25);
        }
        public async Task <Resultado <MovimientoDto> > CargarProducto(MovimientoRequest movimiento)
        {
            List <string> errores = new List <string>();
            Guid          bodegaId;
            Guid          productoId;
            BodegaDto     bodega   = null;
            ProductoDto   producto = null;

            if (Guid.TryParse(movimiento.BodegaId, out bodegaId))
            {
                bodega = await _repositorioBodega.BuscarBodega(bodegaId);

                if (bodega == null)
                {
                    errores.Add($"La bodega con Id {movimiento.BodegaId} no esta en el sistema");
                }
            }
            else
            {
                errores.Add("La Id de la bodega no tiene el formato correcto");
            }
            if (Guid.TryParse(movimiento.ProductoId, out productoId))
            {
                producto = await _repositorioProducto.BuscarProducto(productoId);

                if (producto == null)
                {
                    errores.Add($"El producto con Id {movimiento.ProductoId} no esta en el sistema");
                }
            }
            else
            {
                errores.Add("La Id del producto no tiene el formato correcto");
            }

            if (movimiento.Cantidad <= 0)
            {
                errores.Add("La cantidad debe ser mayor a 0");
            }

            if (movimiento.Valor <= 0)
            {
                errores.Add("El valor debe ser mayor a 0");
            }

            if (errores.Count > 0)
            {
                return(Resultado <MovimientoDto> .Failure(errores));
            }

            InventarioDto inventario = await _repositorioInventario.ObtenerInventario(bodega.Id, producto.Id);

            int capacidadDisponible = 0;

            if (inventario != null)
            {
                capacidadDisponible = bodega.CapacidadMaxima - inventario.Cantidad;
            }
            else
            {
                capacidadDisponible = bodega.CapacidadMaxima;
            }

            if (movimiento.Cantidad > capacidadDisponible)
            {
                return(Resultado <MovimientoDto> .Failure("La cantidad de producto a ingresar supera el maximo de productos totales permitido en la bodega"));
            }

            MovimientoDto movimientoCrear = new MovimientoDto
            {
                Id = Guid.NewGuid(),
                FechaMovimiento = DateTime.Now,
                Bodega          = bodega,
                Producto        = producto,
                Cantidad        = movimiento.Cantidad,
                Valor           = movimiento.Valor,
                Tipo            = TipoMovimiento.Ingreso
            };

            MovimientoDto movimientoCreado = await _repositorioInventario.GuardarMovimiento(movimientoCrear);

            if (movimientoCreado != null)
            {
                await _repositorioInventario.ActualizarInvetario(movimientoCreado);

                return(Resultado <MovimientoDto> .Success(movimientoCreado));
            }
            else
            {
                errores.Add("Se ha presnetado un problema al guardar el movimiento");
                return(Resultado <MovimientoDto> .Failure(errores));
            }
        }