예제 #1
0
 public IActionResult Edit(string id, MalwareEditViewModel model)
 {
     try
     {
         //verificamos que el id no este vacio
         if (id != null)
         {
             //obtenemos el malware
             var malware = malwareManager.GetByMd5(id);
             //si elmalware no esta vacio generamos el model
             if (malware != null)
             {
                 malware.Name          = model.Malware.Name;
                 malware.Date          = model.Malware.Date;
                 malware.MalwareLevel  = model.Malware.MalwareLevel;
                 malware.MalwareStatus = model.Malware.MalwareStatus;
                 malware.User_Id       = model.Malware.User_Id;
                 malwareManager.Context.SaveChanges();
                 TempData["editado"] = "El malware se ha editado correctamente";
                 _log.LogInformation("Malware editado correctamente: Id " + id.ToString());
                 return(RedirectToAction("Index"));
             }
             //si el malware no existe redirigimos a index
             else
             {
                 return(RedirectToAction("Index"));
             }
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         _log.LogError(ex.Message, ex);
         return(RedirectToAction("Index"));
     }
 }
예제 #2
0
        public IActionResult Edit(string id)
        {
            try
            {
                //verificamos que el id no este vacio
                if (id != null)
                {
                    //obtenemos el malware
                    var malware = malwareManager.GetByMd5(id);
                    //si elmalware no esta vacio generamos el model
                    if (malware != null)
                    {
                        //Obtenemos los usuarios y los pasamos a una lista
                        var users = usrManager.GetAll().Select(e => new UserList
                        {
                            Id       = e.Id.ToString(),
                            UserName = e.UserName
                        }).ToList();

                        var userList = new List <SelectListItem>();

                        foreach (var item in users)
                        {
                            userList.Add(new SelectListItem {
                                Text = item.UserName, Value = item.Id
                            });
                        }

                        var model = new MalwareEditViewModel
                        {
                            UserList = userList,
                            Malware  = new Malware
                            {
                                Id            = malware.Id,
                                Name          = malware.Name,
                                Date          = malware.Date,
                                User          = malware.User,
                                User_Id       = malware.User_Id,
                                MalwareStatus = malware.MalwareStatus,
                                MalwareLevel  = malware.MalwareLevel,
                                MD5           = malware.MD5
                            },
                        };

                        return(View(model));
                    }
                    //si el malware no existe redirigimos a index
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message, ex);
                return(RedirectToAction("Index"));
            }
        }