Ejemplo n.º 1
0
        public async Task <bool> UpdateGigAsync(int id, GigEditViewModel model)
        {
            using (var context = new ApplicationDbContext())
            {
                var entity = await context
                             .Gigs
                             .Where(e => e.GigId == id && e.OwnerId == _userId)
                             .FirstOrDefaultAsync();

                entity.Date       = model.Date;
                entity.PostalCode = model.PostalCode;

                return(await context.SaveChangesAsync() == 1);
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult Put(GigEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateGigService();

            if (!service.UpdateGig(model))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Put(int id, GigEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var gigService = CreateGigService();

            if (await gigService.UpdateGigAsync(id, model))
            {
                return(Ok());
            }

            return(InternalServerError());
        }
Ejemplo n.º 4
0
        // GET: Gigs/Edit/5
        public ActionResult Edit(int id)
        {
            var service = CreateGigService();
            var detail  = service.GetGigById(id);

            var model = new GigEditViewModel
            {
                GigId     = detail.GigId,
                VenueName = detail.VenueName,
                Date      = detail.Date,
                City      = detail.City,
                State     = detail.State,
                Zip       = detail.Zip
            };

            return(View(model));
        }
Ejemplo n.º 5
0
        public bool UpdateGig(GigEditViewModel model)
        {
            using (var context = new ApplicationDbContext())
            {
                var entity = context
                             .Gigs
                             .FirstOrDefault(e => e.GigId == model.GigId && e.OwnerId == _userId);

                entity.VenueName = model.VenueName;
                entity.Date      = model.Date;
                entity.City      = model.City;
                entity.State     = model.State;
                entity.Zip       = model.Zip;

                return(context.SaveChanges() == 1);
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Edit(int id, GigEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateGigService();

            if (await service.UpdateGigAsync(id, model))
            {
                TempData["SaveResult"] = "Your gig was updated";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your gig could not be updated.");
            return(View(model));
        }
Ejemplo n.º 7
0
        public GigEditViewModel GetGigById(int gigId)
        {
            using (var context = new ApplicationDbContext())
            {
                var entity = context
                             .Gigs
                             .Single(e => e.GigId == gigId && e.OwnerId == _userId);

                var gig = new GigEditViewModel
                {
                    GigId     = entity.GigId,
                    VenueName = entity.VenueName,
                    Date      = entity.Date,
                    City      = entity.City,
                    State     = entity.State,
                    Zip       = entity.Zip,
                };

                return(gig);
            }
        }
Ejemplo n.º 8
0
        public ActionResult Edit(int id, GigEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.GigId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateGigService();

            if (service.UpdateGig(model))
            {
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your gig could not be updated.");

            return(View(model));
        }