예제 #1
0
 public async Task <ActionResult> Edit(int id, EditActivityFormViewModel activity)
 {
     if (!ModelState.IsValid)
     {
         return(View("Edit", activity));
     }
     else
     {
         using (var db = new ApplicationDbContext())
         {
             var mapper = Automapper.GetInstance();
             var model  = mapper.Map <Activity>(activity);
             db.Entry(model).State = EntityState.Modified;
             await db.SaveChangesAsync();
         }
         return(RedirectToAction("Index"));
     }
 }
예제 #2
0
        public async Task <ActionResult> Create(CreateActivityViewModels activity)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", activity));
            }
            else
            {
                using (var db = new ApplicationDbContext())
                {
                    var mapper = Automapper.GetInstance();
                    var model  = mapper.Map <Activity>(activity);



                    db.Activities.Add(model);
                    await db.SaveChangesAsync();
                }
                return(RedirectToAction("Index", activity));
            }
        }
예제 #3
0
        // GET: Activity/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var activity = await db.Activities.FindAsync(id);

                if (activity == null)
                {
                    return(View("Error"));
                }
                var mapper = Automapper.GetInstance();
                var model  = mapper.Map <EditActivityFormViewModel>(activity);
                model.Rooms = await db.Rooms.Select(x => new SelectListItem {
                    Text = x.Name, Value = x.RoomId.ToString()
                }).ToListAsync();

                model.Coachs = await db.Coachs.Select(x => new SelectListItem {
                    Text = x.Name, Value = x.CoachId.ToString()
                }).ToListAsync();

                return(View(model));
            }
        }