示例#1
0
        private async Task <IActionResult> UpdateGig()
        {
            Gig.User = await _userManager.GetUserAsync(User);

            _context.Attach(Gig).State = EntityState.Modified;
            foreach (var package in Gig.Packages)
            {
                _context.Attach(package).State = EntityState.Modified;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GigExists(Gig.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToPage("Edit", new { id = Gig.Id }));
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Package = await _context.Packages
                      .Include(p => p.Gig).FirstOrDefaultAsync(m => m.Id == id);

            var isAuthorized = await _authorizationService.AuthorizeAsync(User, Package.Gig, "IsOwner");

            if (isAuthorized.Succeeded)
            {
                if (Package != null)
                {
                    _context.Packages.Remove(Package);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToPage("../Edit", new { id = Package.GigId }));
            }
            else if (User.Identity.IsAuthenticated)
            {
                return(new ForbidResult());
            }
            else
            {
                return(new ChallengeResult());
            }
        }
示例#3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var existingGig = await _context.Gigs
                              .Include(g => g.Packages)
                              .AsNoTracking()
                              .FirstOrDefaultAsync(g => g.Id == Package.GigId);

            var isAuthorized = await _authorizationService.AuthorizeAsync(User, existingGig, "IsOwner");

            if (isAuthorized.Succeeded)
            {
                _context.Packages.Add(Package);
                //existingGig.StartingPrice = existingGig.Packages.Append(Package).Min(p => p.Price);
                _context.Update(existingGig);
                await _context.SaveChangesAsync();

                return(RedirectToPage("../Edit", new { id = Package.GigId }));
            }
            else if (User.Identity.IsAuthenticated)
            {
                return(new ForbidResult());
            }
            else
            {
                return(new ChallengeResult());
            }
        }
示例#4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("OnGet"));
            }
            Gig.User = await _userManager.GetUserAsync(User);

            var basicPackage = new Package()
            {
                Name    = "Basic",
                Details = "This is an example package. You should edit this and all the fields below.",
                Gig     = Gig,
            };

            Gig.Packages = new List <Package>()
            {
                basicPackage
            };
            Gig.Reviews = new List <Review>();
            _context.Gigs.Add(Gig);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Edit", new { id = Gig.Id }));
        }
示例#5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Gig = await _context.Gigs.FindAsync(id);

            if (Gig != null)
            {
                _context.Gigs.Remove(Gig);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("/Users/Dashboard"));
        }
示例#6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Order.Buyer = await _userManager.GetUserAsync(User);

            Order.Status  = Status.Due;
            Order.DueDate = DateTime.UtcNow.AddDays(DeliveryDays);

            _context.Orders.Add(Order);
            await _context.SaveChangesAsync();

            return(RedirectToPage("/Index"));
        }
示例#7
0
        public async Task <IActionResult> OnPostSendAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Message.Receiver = await _userManager.FindByNameAsync(ReceiverName);

            Message.Sender = await _userManager.GetUserAsync(User);

            _context.Messages.Add(Message);
            await _context.SaveChangesAsync();

            //send updated partial
            return(OnGetUserConvo(ReceiverName));
        }
示例#8
0
        public async Task <IActionResult> OnPostReview()
        {
            if (!ModelState.IsValid)
            {
                if (Review.GigId > 0)
                {
                    return(RedirectToPage("Details", new { id = Review.GigId }));
                }
                else
                {
                    return(RedirectToPage("/Index"));
                }
            }

            Review.User = await _userManager.GetUserAsync(User);

            _context.Reviews.Add(Review);
            await _context.SaveChangesAsync();

            return(RedirectToPage("Details", new { id = Review.GigId }));
        }