Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, /* [Bind("Id,Name,Description,PartyLogoPath,IsActive")]*/ PoliticPartyCreateViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUploadedFile(model);
                if (uniqueFileName == null)
                {
                    uniqueFileName = model.Photo;
                }

                var politicParty = new PoliticParty()
                {
                    Id            = model.Id,
                    Name          = model.Name,
                    Description   = model.Description,
                    PartyLogoPath = uniqueFileName,
                    IsActive      = model.IsActive
                };
                try
                {
                    _politicPartyService.UdatePoliticParty(politicParty);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PoliticPartyExists(politicParty.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public PoliticParty DeletePoliticParty(PoliticParty politicParty)
        {
            politicParty.IsActive = false;
            _politicPartyRepository.Update(politicParty);
            var candidates = _candidateRepository.GetAll().Where(c => c.PoliticPartyId == politicParty.Id)
                             .Select(c => new Candidate
            {
                Id                = c.Id,
                IsActive          = false,
                Name              = c.Name,
                LastName          = c.LastName,
                PoliticPartyId    = c.PoliticPartyId,
                PositionId        = c.PositionId,
                ProfilePhothoPath = c.ProfilePhothoPath
            }).ToList();


            _candidateRepository.Update(candidates);
            return(politicParty);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(PoliticPartyCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUploadedFile(model);
                if (uniqueFileName == null)
                {
                    uniqueFileName = "PartidoNull.png";
                }
                PoliticParty politicParty = new PoliticParty
                {
                    Name          = model.Name,
                    Description   = model.Description,
                    PartyLogoPath = uniqueFileName,
                    IsActive      = model.IsActive
                };

                _politicPartyService.InsertPoliticParty(politicParty);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Ejemplo n.º 4
0
 public PoliticParty UdatePoliticParty(PoliticParty politicParty)
 {
     return(_politicPartyRepository.Update(politicParty));
 }
Ejemplo n.º 5
0
 public PoliticParty InsertPoliticParty(PoliticParty politicParty)
 {
     return(_politicPartyRepository.Insert(politicParty));
 }