Exemplo n.º 1
0
        public async Task <IActionResult> PutStudent(Guid id, Student student)
        {
            if (id != student.Id)
            {
                return(BadRequest());
            }

            _context.Entry(student).State = EntityState.Modified;

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

            return(NoContent());
        }
        public async Task<IActionResult> PutVendedorDepartamento(int id, VendedorDepartamento vendedorDepartamento)
        {
            if (id != vendedorDepartamento.Id)
            {
                return BadRequest();
            }

            _context.Entry(vendedorDepartamento).State = EntityState.Modified;

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

            return NoContent();
        }
        public async Task <IActionResult> PutCategoriaProducto(int id, CategoriaProducto categoriaProducto)
        {
            if (id != categoriaProducto.Id)
            {
                return(BadRequest());
            }

            _context.Entry(categoriaProducto).State = EntityState.Modified;

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

            return(NoContent());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> PutInventario(int id, Inventario inventario)
        {
            if (id != inventario.Id)
            {
                return(BadRequest());
            }

            _context.Entry(inventario).State = EntityState.Modified;

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

            return(NoContent());
        }
        public async Task <ActionResult <ReciboCobranzas> > PostReciboCobranzas(ReciboCobranzas reciboCobranzas)
        {
            try
            {
                List <ImputacionComprobantesVenta> imputaciones = reciboCobranzas.Imputaciones;
                List <MovimientoCaja> movimientoCajas           = reciboCobranzas.movimientosCaja;
                Cliente cliente = reciboCobranzas.Cliente;
                reciboCobranzas.Cliente         = null;
                reciboCobranzas.Imputaciones    = null;
                reciboCobranzas.movimientosCaja = null;

                _context.reciboCobranzas.Add(reciboCobranzas);
                cliente.saldoCC -= reciboCobranzas.totalComprobante;
                _context.Entry(cliente).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                foreach (ImputacionComprobantesVenta imputacion in imputaciones)
                {
                    imputacion.ReciboCobranzasId     = reciboCobranzas.Id;
                    _context.Entry(imputacion).State = EntityState.Added;

                    imputacion.FacturaVenta.totalCancelado += imputacion.totalImputado;
                    if (imputacion.FacturaVenta.totalCancelado == imputacion.FacturaVenta.totalComprobante)
                    {
                        imputacion.FacturaVenta.EstadoFacturaId = 2;
                    }
                    _context.Entry(imputacion.FacturaVenta).State = EntityState.Modified;

                    await _context.SaveChangesAsync();
                }

                foreach (MovimientoCaja movimientoCaja in movimientoCajas)
                {
                    movimientoCaja.ReciboCobranzasId = reciboCobranzas.Id;
                    movimientoCaja.entra             = true;
                    movimientoCaja.sale = false;
                    _context.Entry(movimientoCaja).State = EntityState.Added;

                    movimientoCaja.Caja.saldo += movimientoCaja.totalMovimiento;
                    _context.Entry(movimientoCaja.Caja).State = EntityState.Modified;


                    await _context.SaveChangesAsync();
                }


                return(CreatedAtAction("GetReciboCobranzas", new { id = reciboCobranzas.Id }, reciboCobranzas));
            }
            catch (Exception es)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        public async Task <ActionResult <OrdenPago> > PostOrdenPago(OrdenPago ordenPago)
        {
            try
            {
                List <ImputacionComprobantesCompra> imputaciones = ordenPago.Imputaciones;
                List <MovimientoCaja> movimientoCajas            = ordenPago.movimientosCaja;
                Proveedor             proveedor = ordenPago.Proveedor;
                ordenPago.Proveedor       = null;
                ordenPago.Imputaciones    = null;
                ordenPago.movimientosCaja = null;

                _context.ordenPago.Add(ordenPago);
                proveedor.saldoCC += ordenPago.totalComprobante;
                _context.Entry(proveedor).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                foreach (ImputacionComprobantesCompra imputacion in imputaciones)
                {
                    imputacion.OrdenPagoId           = ordenPago.Id;
                    _context.Entry(imputacion).State = EntityState.Added;

                    imputacion.FacturaCompras.totalCancelado += imputacion.totalImputado;
                    if (imputacion.FacturaCompras.totalCancelado == imputacion.FacturaCompras.totalComprobante)
                    {
                        imputacion.FacturaCompras.EstadoFacturaId = 2;
                    }
                    _context.Entry(imputacion.FacturaCompras).State = EntityState.Modified;

                    await _context.SaveChangesAsync();
                }

                foreach (MovimientoCaja movimientoCaja in movimientoCajas)
                {
                    movimientoCaja.OrdenPagoId           = ordenPago.Id;
                    movimientoCaja.entra                 = false;
                    movimientoCaja.sale                  = true;
                    _context.Entry(movimientoCaja).State = EntityState.Added;

                    movimientoCaja.Caja.saldo -= movimientoCaja.totalMovimiento;
                    _context.Entry(movimientoCaja.Caja).State = EntityState.Modified;


                    await _context.SaveChangesAsync();
                }

                return(CreatedAtAction("GetOrdenPago", new { id = ordenPago.Id }, ordenPago));
            }
            catch (Exception es)
            {
                throw;
            }
        }
Exemplo n.º 7
0
        public async Task <string> CreateType(TypeCreateRequest request)
        {
            var type = new productTypes()
            {
                idType   = request.IdType,
                typeName = request.Name,
            };

            _context.productTypes.Add(type);
            await _context.SaveChangesAsync();

            return(type.idType);
        }
Exemplo n.º 8
0
        public async Task <string> CreateSize(SizeCreateRequest request)
        {
            var size = new productSize()
            {
                idSize   = request.IdSize,
                sizeName = request.Name,
            };

            _context.productSize.Add(size);
            await _context.SaveChangesAsync();

            return(size.idSize);
        }
Exemplo n.º 9
0
        public async Task <string> Create(ColorCreateRequest request)
        {
            var color = new productColor()
            {
                idColor   = request.IdColor,
                colorName = request.Name,
            };

            _context.productColor.Add(color);
            await _context.SaveChangesAsync();

            return(color.idColor);
        }
Exemplo n.º 10
0
        public async Task <string> CreateBrand(BrandCreateRequest request)
        {
            var brand = new productBrand()
            {
                idBrand     = request.IdBrand,
                brandName   = request.Name,
                brandDetail = request.Details,
            };

            _context.productBrand.Add(brand);
            await _context.SaveChangesAsync();

            return(brand.idBrand);
        }
Exemplo n.º 11
0
        public async Task <string> Create(CategoryCreateRequest request)
        {
            var category = new productCategories()
            {
                idCategory   = request.idCategory,
                categoryName = request.categoryName
            };

            //Save image

            _context.productCategories.Add(category);
            await _context.SaveChangesAsync();

            return(category.idCategory);
        }
Exemplo n.º 12
0
        public async Task <string> CreateVoucher(VoucherCreateRequest request)
        {
            var vouchers = new vouchers()
            {
                idVoucher   = request.idVoucher,
                price       = request.price,
                expiredDate = request.expiredDate,
                isUse       = 0
            };

            _context.vouchers.Add(vouchers);
            await _context.SaveChangesAsync();

            return(vouchers.idVoucher);
        }
Exemplo n.º 13
0
        public async Task <ActionResult <UserInfo> > CreateUser(UserInfo model)
        {
            var user = new ApplicationUser {
                UserName = model.username, Email = model.username
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                foreach (var rol in model.roles)
                {
                    await _userManager.AddToRoleAsync(user, rol.rol);
                }
                foreach (Vendedor vendedor in model.vendedores)
                {
                    _context.userVendedor.Add(new UserVendedor
                    {
                        Vendedor = await _context.vendedor.FirstAsync(x => x.Id == vendedor.Id),
                        userName = model.username
                    });
                }
                foreach (Deposito deposito in model.depositos)
                {
                    _context.userDeposito.Add(new UserDeposito
                    {
                        Deposito = await _context.deposito.FirstAsync(x => x.Id == deposito.Id),
                        userName = model.username
                    });
                }

                foreach (Caja caja in model.cajas)
                {
                    _context.userCaja.Add(new UserCaja
                    {
                        Caja     = await _context.caja.FirstAsync(x => x.Id == caja.Id),
                        userName = model.username
                    });
                }
                await _context.SaveChangesAsync();

                return(model);
            }
            else

            {
                return(BadRequest("Username or password invalid"));
            }
        }
        public async Task <ActionResult> Post(City city)
        {
            try
            {
                _context.Cities.Add(city);


                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetById), new { id = city.Id }, city));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <OperationResult <VenueOperationStatus, int> > Create(VenueModel model)
        {
            var venue = new Venue
            {
                Name = model.Name + _settings.NamePostfix,
                City = model.City
            };

            _dbContext.Venues.Add(venue);
            await _dbContext.SaveChangesAsync();

            return(new OperationResult <VenueOperationStatus, int>
            {
                Status = VenueOperationStatus.Success,
                Result = venue.Id
            });
        }
Exemplo n.º 16
0
        public async Task <bool> Handle(UpdateNews request, CancellationToken cancellationToken)
        {
            _dbContext.News.Update(request.News);
            await _dbContext.SaveChangesAsync(cancellationToken);

            Log.Information("UpdataNews => completed successfully");
            return(true);
        }
        public async Task AddViewcount(int idProduct)
        {
            var product = await _context.products.FindAsync(idProduct);

            product.ViewCount += 1;
            await _context.SaveChangesAsync();
        }
Exemplo n.º 18
0
        public async Task <IActionResult> PutListaPrecios(int id, ListaPrecios listaPrecios)
        {
            if (id != listaPrecios.Id)
            {
                return(BadRequest());
            }

            _context.Entry(listaPrecios).State = EntityState.Modified;
            listaPrecios.DetalleListaPrecios.ForEach(x =>
            {
                if (x.Id == 0)
                {
                    _context.Entry(x).State = EntityState.Added;
                }
                else
                {
                    _context.Entry(x).State = EntityState.Modified;
                }
            });
            var detallesId      = listaPrecios.DetalleListaPrecios.Select(x => x.Id).ToList();
            var detallesABorrar = _context.detalleListaPrecios.Where(x => !detallesId.Contains(x.Id) && x.ListaPreciosId == listaPrecios.Id).ToList();

            _context.detalleListaPrecios.RemoveRange(detallesABorrar);

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

            return(NoContent());
        }
Exemplo n.º 19
0
        public async Task <IActionResult> PutFormulaProducto(int id, FormulaProducto formulaProducto)
        {
            if (id != formulaProducto.Id)
            {
                return(BadRequest());
            }
            _context.Entry(formulaProducto).State = EntityState.Modified;

            foreach (DetalleFormula detalle in formulaProducto.DetallesFormula)
            {
                if (detalle.Id == 0)
                {
                    _context.Entry(detalle).State = EntityState.Added;
                }
                else
                {
                    _context.Entry(detalle).State = EntityState.Modified;
                }
            }

            var detallesId      = formulaProducto.DetallesFormula.Select(x => x.Id).ToList();
            var detallesABorrar = _context.detalleFormula.Where(x => !detallesId.Contains(x.Id) && x.FormulaProductoId == formulaProducto.Id).ToList();

            _context.detalleFormula.RemoveRange(detallesABorrar);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FormulaProductoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 20
0
        //public async Task<int> Create(CheckoutRequest request)
        //{

        //    List<CartItemViewModel> currentCart = new List<CartItemViewModel>();
        //    if (request.OrderDetails != null)
        //        currentCart = JsonConvert.DeserializeObject<List<CartItemViewModel>>(request.OrderDetails);
        //    var orderdetail = new List<OrderDetail>();

        //    var user = _context.users.FirstOrDefault(x => x.UserName == request.UserName);
        //    var userid = user.Id;

        //    foreach (var item in currentCart)
        //    {
        //        orderdetail.Add(new OrderDetail()
        //        {
        //            ProductId = item.ProductId,
        //            Quantity = item.Quantity,
        //            Price = item.Price,
        //        });
        //    }

        //    var order = new Order()
        //    {
        //        UserName = request.UserName,
        //        ShipAddress = request.Address,
        //        ShipEmail = request.Email,
        //        ShipName = request.Name,
        //        ShipPhoneNumber = request.PhoneNumber,
        //        OrderDate = DateTime.Now,
        //        OrderDetails = orderdetail,
        //        LanguageId=request.LanguageId,
        //        UserId=userid
        //    };
        //    //Save image

        //    _context.Orders.Add(order);
        //    await _context.SaveChangesAsync();
        //    return order.Id;
        //}

        public async Task <int> Delete(string id)
        {
            var or = await _context.odersList.FindAsync(id);

            if (or == null)
            {
                throw new WebAPIException($"Cannot find a color: {id}");
            }

            _context.odersList.Remove(or);
            return(await _context.SaveChangesAsync());;
        }
Exemplo n.º 21
0
        public async Task <IActionResult> Post([FromBody] Match match)
        {
            if (ModelState.IsValid)
            {
                _context.Matches.Add(match);
                await _context.SaveChangesAsync();

                return(Ok("Матч создан."));
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 22
0
        public async Task <IActionResult> PutVendedor(int id, Vendedor vendedor)
        {
            if (id != vendedor.Id)
            {
                return(BadRequest());
            }


            string rutaActualImagen = _context.vendedor.Where(x => x.Id == id).Select(x => x.Foto).ToList()[0];

            if (rutaActualImagen != vendedor.Foto)
            {
                var fotoImagen = Convert.FromBase64String(vendedor.Foto);
                vendedor.Foto = await almacenadorDeArchivos.EditarArchivo(fotoImagen,
                                                                          "jpg", "vendedores", rutaActualImagen);
            }


            _context.Entry(vendedor).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VendedorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 23
0
        public async Task <int> AddImage(int idProduct, ProductImageCreateRequest request)
        {
            var ProductPhoto = new productPhotos()
            {
                Caption      = request.Caption,
                uploadedTime = DateTime.Now,
                IsDefault    = request.IsDefault,
                idProduct    = idProduct,
                SortOrder    = request.SortOrder,
            };

            if (request.ImageFile != null)
            {
                ProductPhoto.ImagePath = await this.SaveFile(request.ImageFile);

                ProductPhoto.FileSize = request.ImageFile.Length;
            }
            _context.productPhotos.Add(ProductPhoto);
            await _context.SaveChangesAsync();

            return(ProductPhoto.Id);
        }
Exemplo n.º 24
0
        public async Task <bool> Handle(AddComment request, CancellationToken cancellationToken)
        {
            try
            {
                await _dbContext.Comments.AddAsync(request.Comments, cancellationToken);

                await _dbContext.SaveChangesAsync(cancellationToken);

                Log.Information("WebApiCQRS,AddComment => completed successfully");
                return(true);
            }
            catch (System.Exception ex)
            {
                Log.Error($"WebApiCQRS,AddComment => {ex.Message}");
                return(false);
            }
        }
Exemplo n.º 25
0
        public async Task SaveMessage(User sender, int receiverId, string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            var directMessage = new DirectMessages()
            {
                SenderId    = sender.Id,
                ReceiverId  = receiverId,
                Message     = message,
                CreatedDate = DateTime.UtcNow
            };

            _context.DirrectMessages.Add(directMessage);
            await _context.SaveChangesAsync();
        }
Exemplo n.º 26
0
        public async Task <ActionResult> Ban([FromBody] BanDto banDto)
        {
            if (banDto == null)
            {
                return(BadRequest());
            }

            banDto.CreatedDate = DateTime.UtcNow;

            var existingBlock = _context.Bans.AsQueryable().FirstOrDefault(x => x.Email == banDto.Email);

            if (existingBlock != null)
            {
                return(Ok(existingBlock));
            }

            await _context.Bans.AddAsync(_mapper.Map <Bans>(banDto));

            await _context.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 27
0
        public async Task <bool> Handle(DeleteNewsById request, CancellationToken cancellationToken)
        {
            try
            {
                var news = await _dbContext.News.FirstOrDefaultAsync(n => n.Id == request.Id);

                if (news != null)
                {
                    _dbContext.News.Remove(news);
                    await _dbContext.SaveChangesAsync(cancellationToken);

                    Log.Information("WebApiCQRS,DeleteCommentById => completed successfully");
                    return(true);
                }
                Log.Information("WebApiCQRS,DeleteNewsById => news = null");
                return(false);
            }
            catch (Exception ex)
            {
                Log.Error($"WebApiCQRS,DeleteNews => {ex.Message}");
                return(false);
            }
        }
Exemplo n.º 28
0
        public async Task <string> AddImage(string productId, ProductImageCreateRequest request)
        {
            var productImage = new productPhotos()
            {
                IdPhoto      = request.idImage,
                idProduct    = request.idProduct,
                uploadedTime = DateTime.Now,
            };

            if (request.ImageFile != null)
            {
                productImage.link = new string("https://localhost:5001" + await this.SaveFile(request.ImageFile));
            }
            _context.productPhotos.Add(productImage);
            await _context.SaveChangesAsync();

            return(productImage.IdPhoto);
        }
        public async Task Add(T entity)
        {
            await context.Set <T>().AddAsync(entity).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }