예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("VotoPropuestaId,PropuestaId,Votacion,UsuarioId,Comentario")] VotoPropuesta votoPropuesta)
        {
            if (id != votoPropuesta.VotoPropuestaId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(votoPropuesta);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VotoPropuestaExists(votoPropuesta.VotoPropuestaId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PropuestaId"] = new SelectList(_context.Propuesta, "PropuestaId", "Titulo", votoPropuesta.PropuestaId);
            ViewData["UsuarioId"]   = new SelectList(_context.AspNetUsers, "Id", "UserName", votoPropuesta.UsuarioId);
            return(View(votoPropuesta));
        }
예제 #2
0
        public async Task <IActionResult> Votar([Bind("VotoPropuestaId,PropuestaId,Votacion,UsuarioId,VotoPropuesta,Comentario")] VotoPropuesta votoPropuesta)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (String.IsNullOrEmpty(votoPropuesta.Comentario))
                    {
                        NotifyError("El voto no pudo ser registrado ya que falto informacion por llenar. Intente de nuevo.", notificationType: NotificationType.error);
                        return(RedirectToAction(nameof(IndexEmpleado)));
                    }
                    else
                    {
                        using (var cl = new HttpClient())
                        {
                            cl.BaseAddress = new Uri(baseurl);
                            var content     = JsonConvert.SerializeObject(votoPropuesta);
                            var buffer      = System.Text.Encoding.UTF8.GetBytes(content);
                            var byteContent = new ByteArrayContent(buffer);
                            byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                            var postTask = cl.PostAsync("api/VotoPropuesta", byteContent).Result;


                            if (postTask.IsSuccessStatusCode)
                            {
                                NotifyDelete("El registro se ha agregado correctamente");
                                return(RedirectToAction(nameof(IndexEmpleado)));
                            }
                            else
                            {
                                NotifyError("Error inesperado. Contacte a su administrador", notificationType: NotificationType.error);
                                return(RedirectToAction(nameof(IndexEmpleado)));
                            }
                        }
                    }
                }
                var user = await userManager.FindByNameAsync(User.Identity.Name);

                List <IdentityUser> listUser = new List <IdentityUser>();
                listUser.Add(user);
                List <Propuesta> listPropuesta = new List <Propuesta>();
                listPropuesta.Add(GetById(votoPropuesta.PropuestaId));
                ViewData["PropuestaId"] = new SelectList(listPropuesta, "PropuestaId", "Beneficios", votoPropuesta.PropuestaId);
                ViewData["UsuarioId"]   = new SelectList(listUser, "Id", "Email", votoPropuesta.UsuarioId);
                return(View(votoPropuesta));
            }
            catch (Exception)
            {
                NotifyError("Error inesperado. Contacte a su administrador", notificationType: NotificationType.error);
                return(RedirectToAction(nameof(IndexEmpleado)));
            }
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("VotoPropuestaId,PropuestaId,Votacion,UsuarioId,Comentario")] VotoPropuesta votoPropuesta)
        {
            if (ModelState.IsValid)
            {
                _context.Add(votoPropuesta);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PropuestaId"] = new SelectList(_context.Propuesta, "PropuestaId", "Titulo", votoPropuesta.PropuestaId);
            ViewData["UsuarioId"]   = new SelectList(_context.AspNetUsers, "Id", "UserName", votoPropuesta.UsuarioId);
            return(View(votoPropuesta));
        }