Beispiel #1
0
        public async Task <IActionResult> MakeQuestions([Bind("Description,Status,ProductId,Id")] Question question)
        {
            if (_context.Questions.First() == null)
            {
                question.Id = 1;
            }
            else
            {
                question.Id = _context.Questions.Last().Id + 1;
            }


            question.Status = 1;
            question.UserId = _context.UserActive().Id;

            if (ModelState.IsValid)
            {
                SendEmail(question.ProductId, question.Description);
                _context.Add(question);
                await _context.SaveChangesAsync();


                return(RedirectToAction("Index", "Questions", new { id = question.ProductId }));
            }


            return(View(Index(question.ProductId)));
        }
Beispiel #2
0
        // GET: Publications/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var publication = await _context.Publication
                              .Include(p => p.User)
                              .FirstOrDefaultAsync(m => m.Id == id);

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

            var user_login = await _context.Users.FirstOrDefaultAsync(m => m.Id == 1);

            if (user_login.Id == 1)
            {
                var view = new View()
                {
                    Id = _context.Views.Count() + 1, UserId = user_login.Id, PublicationId = publication.Id
                };
                _context.Add(view);
                await _context.SaveChangesAsync();
            }

            return(View(publication));
        }
        public async Task <IActionResult> Create([Bind("Name,Id")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("UserId,Description,Facebook,Twitter,Instagram,Avatar,Id")] Profile profile)
        {
            if (ModelState.IsValid)
            {
                _context.Add(profile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Email", profile.UserId);
            return(View(profile));
        }
        public async Task <IActionResult> Create([Bind("Description,QuestionId,Id")] Answer answer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(answer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["QuestionId"] = new SelectList(_context.Questions, "Id", "Id", answer.QuestionId);
            return(View(answer));
        }
        public async Task <IActionResult> Create([Bind("Id,ProductId,Route")] Photo photo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(photo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Id", photo.ProductId);
            return(View(photo));
        }
Beispiel #7
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Email,Role,Country,IsActive,CityId,Id")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", user.CityId);
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("UserId,Type,Checked,Messasge,Id")] Notification notification)
        {
            if (ModelState.IsValid)
            {
                _context.Add(notification);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Email", notification.UserId);
            return(View(notification));
        }
        public async Task <IActionResult> Create([Bind("CategoryId,Name,Id")] SubCategory subCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", subCategory.CategoryId);
            return(View(subCategory));
        }
        public async Task <IActionResult> Create([Bind("ExpireDate,Periodicity,RelatedCities,Id,Tags")] Alert alert)
        {
            if (ModelState.IsValid)
            {
                alert.UserId = _context.UserActive().Id;
                _context.Add(alert);
                int i = _context.UserActive().Alerts.Count();
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(alert));
        }
Beispiel #11
0
        public async Task <IActionResult> Create([Bind("Description,ProductId,AlertId,Id")] Tag tag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AlertId"]   = new SelectList(_context.Alerts, "Id", "Id", tag.AlertId);
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Id", tag.ProductId);
            return(View(tag));
        }
        public async Task <IActionResult> Create([Bind("PublicationId,UserId,Id")] View view)
        {
            if (ModelState.IsValid)
            {
                _context.Add(view);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PublicationId"] = new SelectList(_context.Publication, "Id", "Id", view.PublicationId);
            ViewData["UserId"]        = new SelectList(_context.Users, "Id", "Email", view.UserId);
            return(View(view));
        }
        public async Task <IActionResult> Create([Bind("Id,SellerId,BuyerId,ProductId")] Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                _context.Add(transaction);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BuyerId"]   = new SelectList(_context.Users, "Id", "Email", transaction.BuyerId);
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Id", transaction.ProductId);
            ViewData["SellerId"]  = new SelectList(_context.Users, "Id", "Email", transaction.SellerId);
            return(View(transaction));
        }
Beispiel #14
0
        public async Task <IActionResult> Create([Bind("Title,Description,Tags,RelatedCities,Price,Units,CategoryId,SubCategoryId,IsExpress,ExpiryDate,Id")] Product product, IFormFile image)
        {
            if (ModelState.IsValid)
            {
                product.Id = 11;

                while (_context.Products.Select(x => x.Id).Contains(product.Id))
                {
                    Random a = new Random();
                    product.Id = (int)a.Next(12, 10000);
                }

                User        s = _context.UserActive();
                Publication p = new Publication()
                {
                    Id     = product.Id, Status = Models.Enum.ProductStatus.Active,
                    UserId = s.Id, User = s
                };
                _context.Publication.Add(p);
                product.PublicationId = p.Id;
                product.CityId        = _context.UserActive().CityId;
                product.Insignia      = Models.Enum.TypeInsignias.New;
                product.Date          = (DateTime.Now);
                product.Status        = Models.Enum.ProductStatus.Active;

                if (image != null && image.Length > 0)
                {
                    var fileName = Path.Combine(_environment.WebRootPath, "users", image.FileName);

                    await image.CopyToAsync(new FileStream(fileName, FileMode.Create));

                    int PId = 11;
                    while (_context.Photos.Select(x => x.Id).Contains(PId))
                    {
                        Random b = new Random();
                        PId = (int)b.Next(12, 10000);
                    }

                    Photo a = new Photo()
                    {
                        Id = PId, ProductId = product.Id, Route = "/users/" + image.FileName
                    };
                    _context.Photos.Add(a);
                }

                if (product.IsExpress == false)
                {
                    product.ExpiryDate = null;
                }
                else
                {
                    product.Insignia = Models.Enum.TypeInsignias.VentaExpress;
                }
                _context.Products.Add(product);
                Notification n = new Notification {
                    UserId = _context.UserActive().Id, Checked = false, Messasge = "Se ha añadido un producto: " + product.Title
                };
                _context.Notifications.Add(n);
                var tags   = product.Tags.Split(',');
                var cities = product.RelatedCities.Split(',');
                foreach (var x in _context.Alerts)
                {
                    var t = x.Tags.Split(',').Intersect(tags);
                    var c = x.RelatedCities.Split(',').Intersect(cities);
                    if (c.Count() != 0 && x.ExpireDate > DateTime.Now)
                    {
                        SendEmail(_context.Users.First(y => y.Id == x.UserId).Email, "Hay un nuevo producto que te puede interesar: " + product.Title + ".\nSe encuentra en la ciudad de " + c.First());
                    }
                    else if (t.Count() != 0 && x.ExpireDate > DateTime.Now)
                    {
                        SendEmail(_context.Users.First(y => y.Id == x.UserId).Email, "Hay un nuevo producto que te puede interesar: " + product.Title + ".\nSe encuentra en la categoría de " + t.First());
                    }
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(product));
        }