Esempio n. 1
0
        // Update
        public IHttpActionResult Put(BuddyEdit buddy)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateBuddyService();

            if (!service.UpdateBuddy(buddy))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Esempio n. 2
0
        // GET: Buddy/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = CreateBuddyService();
            var detail  = service.GetBuddyById(id);
            var model   =
                new BuddyEdit
            {
                BuddyId         = detail.BuddyId,
                Name            = detail.Name,
                CurrentLocation = detail.CurrentLocation,
                IsApproved      = detail.IsApproved,
                IsMale          = detail.IsMale,
                Age             = detail.Age
            };

            return(View(model));
        }
Esempio n. 3
0
        public bool UpdateBuddy(BuddyEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Buddies
                    .SingleOrDefault(b => b.BuddyId == model.BuddyId && b.UserId == _userId);

                entity.Name            = model.Name;
                entity.CurrentLocation = model.CurrentLocation;
                entity.IsApproved      = model.IsApproved;
                entity.IsMale          = model.IsMale;
                entity.Age             = model.Age;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 4
0
        public ActionResult Edit(int id, BuddyEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateBuddyService();

            if (service.UpdateBuddy(model))
            {
                TempData["SaveResult"] = "Your profile was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your profile could not be updated.");
            return(View());
        }