Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, GenderViewModel viewModel)
        {
            if (id != viewModel.GenderId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Gender model = new Gender();
                    _mapper.Map(viewModel, model);


                    _context.Update(model);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GenderExists(viewModel.GenderId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
Exemplo n.º 2
0
 public async Task <GenderViewModel> EncodeGenderId(GenderViewModel gender)
 {
     return(await Task.Run(() =>
     {
         gender.GenderId = GuidEncoder.Encode(gender.GenderId);
         return gender;
     }));
 }
Exemplo n.º 3
0
        // GET: Genders
        public async Task <IActionResult> Index()
        {
            GenderViewModel viewModel = new GenderViewModel();

            var genders = await _context.Gender.ToArrayAsync();

            IEnumerable <GenderViewModel> gendersVM = _mapper.Map <Gender[], IEnumerable <GenderViewModel> >(genders);

            return(View(gendersVM));
        }
Exemplo n.º 4
0
        public static Gender MappFromGenderViewModelToGenderBO(GenderViewModel gender)
        {
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <GenderViewModel, Gender>();
            });

            var genderBussines = Mapper.Map <GenderViewModel, Gender>(gender);

            return(genderBussines);
        }
Exemplo n.º 5
0
        public ActionResult Customers()
        {
            GlobalViewModel globalModel = new GlobalViewModel();

            //List<GenderViewModel> genders = new List<GenderViewModel>();
            //List<LanguageViewModel> languages = new List<LanguageViewModel>();
            try
            {
                myConnection.Open();

                SqlCommand    myCommand = new SqlCommand("SELECT * FROM Gender", myConnection);
                SqlDataReader myReader  = myCommand.ExecuteReader();

                while (myReader.Read())
                {
                    GenderViewModel gender = new GenderViewModel();
                    gender.ID          = myReader["GenderID"].ToString();
                    gender.Description = myReader["GenderDescription"].ToString();
                    //genders.Add(gender);

                    globalModel.genders.Add(gender);
                }

                myConnection.Close();
                myConnection.Open();

                SqlCommand    myNewCommand = new SqlCommand("SELECT * FROM Preferred_Language", myConnection);
                SqlDataReader myNewReader  = myNewCommand.ExecuteReader();

                while (myNewReader.Read())
                {
                    LanguageViewModel language = new LanguageViewModel();
                    language.ID   = myNewReader["LanguageID"].ToString();
                    language.Name = myNewReader["LanguageName"].ToString();
                    //languages.Add(language);

                    globalModel.languages.Add(language);
                }
            }
            catch (Exception err)
            {
                ViewBag.Message = err.Message;
            }
            finally
            {
                myConnection.Close();
            }

            return(View(globalModel));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create(GenderViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Gender model = new Gender();
                _mapper.Map(viewModel, model);

                _context.Add(model);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
Exemplo n.º 7
0
        protected override object GetUpdateDialogView()
        {
            if (ViewModel is GendersViewModel viewModel && viewModel.SelectedModel != null)
            {
                var genderVm = new GenderViewModel()
                {
                    Id   = viewModel.SelectedModel.Id,
                    Name = viewModel.SelectedModel.Name
                };

                return(new GenderDialog("Изменить", genderVm));
            }

            return(null);
        }
Exemplo n.º 8
0
        // GET: Genders/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var model = await _context.Gender
                        .FirstOrDefaultAsync(m => m.GenderId == id);

            if (model == null)
            {
                return(NotFound());
            }

            GenderViewModel viewModel = new GenderViewModel();

            _mapper.Map(model, viewModel);

            return(View(viewModel));
        }