Esempio n. 1
0
 public BuyOrderServices(SocialNetworkDeveloperContext context, IMapper mapper, IEmail email, IUser user, IPublication publication, ITwilio twilioServices)
 {
     _context             = context;
     _mapper              = mapper;
     _emailServices       = email;
     _userServices        = user;
     _publicationServices = publication;
     _twilioServices      = twilioServices;
 }
Esempio n. 2
0
        public async Task <bool> ReceivedBuyer(ReceivedBuyerDTO receivedBuyerDTO)
        {
            try
            {
                using (var db = new SocialNetworkDeveloperContext())
                {
                    using (var transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            var buyOrder = await db.OrdenesCompras.FirstOrDefaultAsync(x => x.IdOrdenCompra == receivedBuyerDTO.IdBuyOrder);

                            if (buyOrder == null)
                            {
                                return(false);
                            }

                            var buyer = await _userServices.GetUserByID((int)buyOrder.IdUsuario);

                            buyOrder.EstadoOrdenCompra = 4; //recibido
                            db.Update(buyOrder).State  = EntityState.Modified;
                            await db.SaveChangesAsync();

                            //actualizacion orden de compra
                            var saleOrder = await db.OrdenesVentas.FirstOrDefaultAsync(x => x.IdOrdenVenta == receivedBuyerDTO.IdSaleOrder);

                            if (saleOrder != null)
                            {
                                saleOrder.EstadoOrdenVenta = 4; //entregado
                                db.Update(saleOrder).State = EntityState.Modified;
                                await db.SaveChangesAsync();
                            }

                            //inserto raiting de publicacion
                            Rating rating = new Rating()
                            {
                                Rating1           = receivedBuyerDTO.Raiting,
                                FechaHoraCreacion = DateTime.Now,
                                IdPublicacion     = buyOrder.IdPublicacion,
                                IdUsuario         = buyOrder.IdUsuario
                            };
                            db.Ratings.Add(rating);
                            await db.SaveChangesAsync();

                            //actualizar publicación
                            //var publication = await _publicationServices.GetPublicationById((int)buyOrder.IdPublicacion);
                            var publication = await db.Publicaciones.FirstOrDefaultAsync(x => x.IdPublicacion == buyOrder.IdPublicacion);

                            //if (publication != null)
                            //{
                            //    publication.Raiting = receivedBuyerDTO.Raiting;

                            //    db.Update(publication).State = EntityState.Modified;
                            //    await _context.SaveChangesAsync();
                            //}


                            var seller = await _userServices.GetUserByID((int)publication.IdUsuario);


                            EmailDTO emailDTO = new EmailDTO()
                            {
                                EmailBuyer     = buyer.CorreoElectronico,
                                EmailSeller    = seller.CorreoElectronico,
                                Title          = string.Format("Su compra/venta de la Publicacion {0} fue Entregada", publication.Titulo),
                                MessagesSeller = string.Format(@"Estimado/a <b>{0}</b> el comprador acaba de confirmar de recibido la mercaderia, gracias por utilizar SNB&S, 
                                                    <br/> 
                                                    Detalle de la Venta 
                                                    <br/>
                                                    Publicación: <b>{1}</b>
                                                    <br/>
                                                    Cantidad: <b>{2}</b>
                                                     <br/>
                                                    Cliente: <b>{3}</b>
                                                    <br/> 
                                                    Telefono: <b>{4}</b>
                                                    <br/>
                                                    Total: <b>{5}</b>"
                                                               , seller.NombreCompleto, publication.Titulo, saleOrder.Cantidad, buyer.NombreCompleto, buyer.TelefonoContacto, saleOrder.TotalVenta),

                                MessagesBuyer = string.Format(@"Estimado/a <b>{0}</b> acaba de confirmar de recibido la mercaderia de su compra, gracias por utilizar SNB&S, 
                                                    <br/> 
                                                    Detalle De la Compra 
                                                    <br/>
                                                    Publicación: <b>{1}</b>
                                                    <br/>
                                                    Cantidad: <b>{2}</b>
                                                    <br/>
                                                    Total: <b>{3}</b>
                                                    <br/>
                                                    Vendedor: <b>{4}</b>
                                                    <br/>
                                                    Telefono: <b>{5}</b>"

                                                              , buyer.NombreCompleto, publication.Titulo, saleOrder.Cantidad, Math.Round((decimal)saleOrder.TotalVenta, 2), seller.NombreCompleto, seller.TelefonoContacto),
                            };
                            //si falla envio correo no registrar la aprobacion
                            var email = await _emailServices.SendEmail(emailDTO);

                            if (!email)
                            {
                                throw new Exception();
                            }

                            //envio sms twilio
                            var smsSeller = await _twilioServices.SendSMS(seller.TelefonoContacto, "Una Venta fue Entregada con Exito en SNB&S");

                            if (!smsSeller)
                            {
                                throw new Exception();
                            }

                            var smsBuyer = await _twilioServices.SendSMS(buyer.TelefonoContacto, "Acabas de Confirmar de Recibido tu Compra en SNB&S");

                            if (!smsBuyer)
                            {
                                throw new Exception();
                            }


                            await transaction.CommitAsync();

                            return(true);
                        }
                        catch (Exception e)
                        {
                            transaction.Rollback();
                            log.ErrorFormat("Error al ejecutar transaccion para confirmar de recibido la mercaderia ReceivedBuyer() {0} : {1} ", e.Source, e.Message);

                            return(false);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("Error al actualizar orden de compra a recibido ReceivedBuyer()  {0} : {1} ", e.Source, e.Message);
                return(false);

                throw;
            }
        }
Esempio n. 3
0
 public AdressServices(SocialNetworkDeveloperContext context)
 {
     _context = context;
 }
Esempio n. 4
0
        public async Task <bool> RejectSale(StatusOrderDTO statusOrderDTO)
        {
            using (var db = new SocialNetworkDeveloperContext())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var saleOrder = await db.OrdenesVentas.FirstOrDefaultAsync(x => x.IdOrdenVenta == statusOrderDTO.IdSaleOrder);

                        if (saleOrder == null)
                        {
                            return(false);
                        }

                        var publication = await _publicationServices.GetPublicationById((int)saleOrder.IdPublicacion);

                        var seller = await _userServices.GetUserByID((int)publication.IdUsuario);

                        saleOrder.EstadoOrdenVenta = 3; //rechazada
                        db.Update(saleOrder).State = EntityState.Modified;
                        await db.SaveChangesAsync();

                        //actualizacion orden de compra
                        var buyOrder = await db.OrdenesCompras.FirstOrDefaultAsync(x => x.IdOrdenCompra == statusOrderDTO.IdBuyOrder);

                        if (buyOrder != null)
                        {
                            buyOrder.EstadoOrdenCompra = 3; //rechazada
                            db.Update(buyOrder).State  = EntityState.Modified;
                            await db.SaveChangesAsync();
                        }
                        var buyer = await _userServices.GetUserByID((int)buyOrder.IdUsuario);


                        EmailDTO emailDTO = new EmailDTO()
                        {
                            EmailBuyer     = buyer.CorreoElectronico,
                            EmailSeller    = seller.CorreoElectronico,
                            Title          = string.Format("Su compra/venta de la Publicaicon {0} fue Rechazada", publication.Titulo),
                            MessagesSeller = string.Format(@"Estimado/a <b>{0}</b> su venta fue <b>rechazada</b> exitosamente, favor notificar al comprador el porque, 
                                                    <br/> 
                                                    Detalle de la Venta 
                                                    <br/>
                                                    Publicación: <b>{1}</b>
                                                    <br/>
                                                    Cantidad: <b>{2}</b>
                                                     <br/>
                                                    Cliente: <b>{3}</b>
                                                    <br/> 
                                                    Telefono: <b>{4}</b>
                                                    <br/>
                                                    Total: <b>{5}</b>"
                                                           , seller.NombreCompleto, publication.Titulo, saleOrder.Cantidad, buyer.NombreCompleto, buyer.TelefonoContacto, Math.Round((decimal)saleOrder.TotalVenta, 2)),

                            MessagesBuyer = string.Format(@"Estimado/a <b>{0}</b> su compra fue <b>rechazada</b> por el vendedor, 
                                                    <br/> 
                                                    Detalle de la Compra 
                                                    <br/>
                                                    Publicación: <b>{1}</b>
                                                    <br/>
                                                    Cantidad: <b>{2}</b>
                                                    <br/>
                                                    Total: <b>{3}</b>
                                                    <br/>
                                                    Vendedor: <b>{4}</b>
                                                    <br/>
                                                    Telefono: <b>{5}</b>"

                                                          , buyer.NombreCompleto, publication.Titulo, saleOrder.Cantidad, Math.Round((decimal)saleOrder.TotalVenta, 2), seller.NombreCompleto, seller.TelefonoContacto),
                        };
                        //si falla envio correo no registrar la aprobacion
                        var email = await _emailServices.SendEmail(emailDTO);

                        if (!email)
                        {
                            throw new Exception();
                        }

                        //envio sms twilio
                        var smsSeller = await _twilioServices.SendSMS(seller.TelefonoContacto, "Acabas de Rechazar una venta en SNB&S");

                        if (!smsSeller)
                        {
                            throw new Exception();
                        }

                        var smsBuyer = await _twilioServices.SendSMS(buyer.TelefonoContacto, "Su compra fue Rechazada por el vendedor en SNB&S");

                        if (!smsBuyer)
                        {
                            throw new Exception();
                        }

                        await transaction.CommitAsync();

                        return(true);
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        log.ErrorFormat("Error al ejecutar transaccion para rechazar venta RejectSale()  {0} : {1} ", e.Source, e.Message);

                        return(false);
                    }
                }
            }
        }
Esempio n. 5
0
        public async Task <bool> AddSale(SaleOrderDTO saleOrderDTO)
        {
            using (var db = new SocialNetworkDeveloperContext())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var seller = await _userServices.GetUserByID((int)saleOrderDTO.IdUsuario);

                        var buyer = await _userServices.GetUserByID((int)saleOrderDTO.IdComprador);

                        var publication = await _publicationServices.GetPublicationById((int)saleOrderDTO.IdPublicacion);

                        var saleOrder = _mapper.Map <OrdenesVenta>(saleOrderDTO);
                        saleOrder.FechaHoraOrdenVenta = DateTime.Now;
                        //saleOrder.TotalVentaConIva = saleOrderDTO.Cantidad * (publication.Precio + (publication.Precio * 0.13m));
                        saleOrder.TotalVenta       = saleOrderDTO.Cantidad * publication.Precio;
                        saleOrder.EstadoOrdenVenta = 1; //pendiente
                        db.OrdenesVentas.Add(saleOrder);
                        await db.SaveChangesAsync();

                        //Creacion de orden de compra
                        OrdenesCompra objCompra = new OrdenesCompra()
                        {
                            IdOrdenVenta         = saleOrder.IdOrdenVenta,
                            IdPublicacion        = publication.IdPublicacion,
                            IdUsuario            = buyer.IdUsuario,
                            FechaHoraOrdenCompra = DateTime.Now,
                            //TotalCompraConIva = saleOrderDTO.Cantidad * (publication.Precio + (publication.Precio * 0.13m)),
                            TotalCompra       = saleOrderDTO.Cantidad * publication.Precio,
                            EstadoOrdenCompra = 1, //pendiente
                            Cantidad          = saleOrderDTO.Cantidad
                        };
                        db.OrdenesCompras.Add(objCompra);
                        await db.SaveChangesAsync();

                        EmailDTO emailDTO = new EmailDTO()
                        {
                            EmailBuyer     = buyer.CorreoElectronico,
                            EmailSeller    = seller.CorreoElectronico,
                            Title          = string.Format("Se Realizo una solicitud de compra/venta de la Publicaicon {0}", publication.Titulo),
                            MessagesSeller = string.Format(@"Estimado/a <b>{0}</b> se ha realizado una solicitud de venta a travez de nuestra aplicación, 
                                                    <br/> 
                                                    Detalle De la Venta 
                                                    <br/>
                                                    Publicación: <b>{1}</b>
                                                    <br/>
                                                    Cantidad: <b>{2}</b>
                                                     <br/>
                                                    Cliente: <b>{3}</b>
                                                    <br/> 
                                                    Telefono: <b>{4}</b>
                                                    <br/> 
                                                    Dirección Entrega: <b>{5}</b>
                                                    <br/> 
                                                    Comentario: <b>{6}</b>"
                                                           , seller.NombreCompleto, publication.Titulo, saleOrderDTO.Cantidad, buyer.NombreCompleto, buyer.TelefonoContacto, saleOrderDTO.DireccionEntrega, saleOrderDTO.Comentario),

                            MessagesBuyer = string.Format(@"Estimado/a <b>{0}</b> se ha realizado una solicitud de compra a travez de nuestra aplicación, 
                                                    <br/> 
                                                    Detalle De la Compra 
                                                    <br/>
                                                    Publicación: <b>{1}</b>
                                                    <br/>
                                                    Cantidad: <b>{2}</b>"

                                                          , buyer.NombreCompleto, publication.Titulo, saleOrderDTO.Cantidad),
                        };
                        //si falla envio correo no registrar la venta
                        var email = await _emailServices.SendEmail(emailDTO);

                        if (!email)
                        {
                            throw new Exception();
                        }

                        //envio sms twilio
                        var smsSeller = await _twilioServices.SendSMS(seller.TelefonoContacto, "Se Realizo una solicitud de compra/venta en SNB&S");

                        if (!smsSeller)
                        {
                            throw new Exception();
                        }

                        var smsBuyer = await _twilioServices.SendSMS(buyer.TelefonoContacto, "Acabas de realizar una solicitud de compra en SNB&S");

                        if (!smsBuyer)
                        {
                            throw new Exception();
                        }

                        await transaction.CommitAsync();

                        return(true);
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                }
            }
        }
 public AuthServices(SocialNetworkDeveloperContext context, IConfiguration configuration)
 {
     _context       = context;
     _configuration = configuration;
 }
 public SubCategoryServices(SocialNetworkDeveloperContext context)
 {
     _context = context;
 }
        //private readonly IMapper _mapper;

        public StatisticsServices(SocialNetworkDeveloperContext context, IMapper mapper)
        {
            _context = context;
            //_mapper = mapper;
        }
Esempio n. 9
0
 public UserServices(SocialNetworkDeveloperContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Esempio n. 10
0
 public PublicationServices(SocialNetworkDeveloperContext context, IMapper mapper)
 {
     _context     = context;
     this._mapper = mapper;
 }