Пример #1
0
        public async Task <ActionResult> DeleteConfirmedAsync(string Id)
        {
            string error = "";
            ConfiguracionsController controlConfiguracion = new ConfiguracionsController(db, userManager);

            var user = await userManager.FindByIdAsync(Id);

            try
            {
                var result = await userManager.DeleteAsync(user);

                if (!result.Succeeded)
                {
                    foreach (var errorA in result.Errors)
                    {
                        error += errorA.Description + "<br>";
                    }
                }
            }
            catch (Exception ex)
            {
                error = controlConfiguracion.SqlErrorHandler(ex);
            }
            HttpContext.Session.SetComplex("error", error);

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Delete(String id)
        {
            String error = "";

            var idInt   = Int32.Parse(id);
            var adjunto = await db.EjecucionAdjunto.FindAsync(idInt);

            if (adjunto != null)
            {
                ConfiguracionsController controlConfiguracion = new ConfiguracionsController(db, userManager);
                try
                {
                    var _path    = Path.Combine(_env.ContentRootPath, "wwwroot/UploadedFiles");
                    var filepath = Path.Combine(_path, adjunto.adjunto);
                    System.IO.File.Delete(filepath);

                    db.EjecucionAdjunto.Remove(adjunto);
                    await db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    error = "Error: " + controlConfiguracion.SqlErrorHandler(ex);
                }
            }
            else
            {
                error = "Error: el adjunto no existe.";
            }

            return(Json(error));
        }
Пример #3
0
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            string error = "";
            ConfiguracionsController controlConfiguracion = new ConfiguracionsController(db, userManager);

            ApplicationRole Rol = await db.Roles.FindAsync(id);

            try
            {
                var claims = await db.RoleClaims.Where(n => n.RoleId == Rol.Id).ToListAsync();

                db.RoleClaims.RemoveRange(claims);
                await db.SaveChangesAsync();

                db.Roles.Remove(Rol);
                await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                error = controlConfiguracion.SqlErrorHandler(ex);
            }
            HttpContext.Session.SetComplex("error", error);

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            string error = "";
            ConfiguracionsController controlConfiguracion = new ConfiguracionsController(db, userManager);
            Nivel nivel = await db.Nivel.FindAsync(id);

            try
            {
                db.Nivel.Remove(nivel);
                await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                error = controlConfiguracion.SqlErrorHandler(ex);
                HttpContext.Session.SetComplex("error", error);
            }
            return(RedirectToAction("Index"));
        }