Esempio n. 1
0
        public IActionResult DeleteConfirmed(int id, EditMenteeView model)
        {
            // Настройка конфигурации AutoMapper
            var config = new MapperConfiguration(cfg => cfg.CreateMap <EditMenteeView, Mentee>());
            //.ForMember("Email", opt => opt.MapFrom(src => src.Login)));
            var mapper = new Mapper(config);
            // Выполняем сопоставление
            Mentee mentee = mapper.Map <EditMenteeView, Mentee>(model);

            unitOfWork.Mentee.Delete(mentee.MenteeId);
            unitOfWork.Save();
            //var mentee = repo.GetMentee(id);//await _context.Mentee.FindAsync(id);
            //unitOfWork.Mentee.Delete(id);// _context.Mentee.Remove(mentee);
            //unitOfWork.Save();//await _context.SaveChangesAsync();
            return(RedirectToAction(nameof(Mentee)));
        }
Esempio n. 2
0
 public ActionResult Edit(EditMenteeView model)
 {
     if (ModelState.IsValid)
     {
         // Настройка конфигурации AutoMapper
         var config = new MapperConfiguration(cfg => cfg.CreateMap <EditMenteeView, Mentee>());
         //.ForMember("Email", opt => opt.MapFrom(src => src.Login)));
         var mapper = new Mapper(config);
         // Выполняем сопоставление
         Mentee mentee = mapper.Map <EditMenteeView, Mentee>(model);
         unitOfWork.Mentee.Update(mentee);
         unitOfWork.Save();
         return(RedirectToAction("Mentee"));
     }
     return(View(model));
 }
Esempio n. 3
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(View());
            }
            // Настройка конфигурации AutoMapper
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Mentee, EditMenteeView>().
                                                 ForMember("Position", opt => opt.MapFrom(c => c.LevelId)));
            var mapper = new Mapper(config);
            var model  = unitOfWork.Mentee.Get(id.Value);
            // Выполняем сопоставление
            EditMenteeView mentee = mapper.Map <Mentee, EditMenteeView>(model);

            //mentee.NewLevel();
            return(View(mentee));
        }
Esempio n. 4
0
        public async Task <IActionResult> Details(int id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Mentee, EditMenteeView>().
                                                 ForMember("Position", opt => opt.MapFrom(c => c.LevelId)));
            var mapper = new Mapper(config);
            var model  = unitOfWork.Mentee.Get(id);
            // Выполняем сопоставление
            EditMenteeView mentee = mapper.Map <Mentee, EditMenteeView>(model);

            //var mentee = unitOfWork.Mentee.Get(id);
            //var mentee = await _context.Mentee
            //    .Include(m => m.Level)
            //    .FirstOrDefaultAsync(m => m.MenteeId == id);
            if (mentee == null)
            {
                return(NotFound());
            }
            return(View(mentee));
        }