コード例 #1
0
        public async Task Invoke(HttpContext context)
        {
            try
            {
                await _next(context);
            }
            catch (Exception ex)
            {
                if (context.IsApiCall())
                {
                    var result = new ApiReturn <object>()
                    {
                        Code    = (int)HttpStatusCode.InternalServerError,
                        Success = false,
                        Message = ex.Message
                    };

                    context.Response.ContentType = "application/json";
                    context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                    await context.Response.WriteAsync(result.ToString());
                }
                else
                {
                    var error = new ErrorVM
                    {
                        RequestId     = Activity.Current?.Id ?? context.TraceIdentifier,
                        Message       = ex.Message,
                        DetailMessage = ex.StackTrace
                    };

                    context.Response.Redirect("/Error/Index");
                }
            }
        }
コード例 #2
0
        public ActionResult ManagerActivate(Guid id)
        {
            BusinessLayerResult <Manager> res = managerm.ActivateManager(id);

            if (res.Errors.Count > 0)
            {
                ErrorVM errorNotifyObj = new ErrorVM()
                {
                    Title = "Geçersiz İşlem",
                    Items = res.Errors
                };

                return(View("Error", errorNotifyObj));
            }

            OkVM okNotifyObj = new OkVM()
            {
                Title          = "Hesap Aktifleştirildi",
                RedirectingUrl = "/Home/ManagerLogin"
            };

            okNotifyObj.Items.Add("Hesabınız aktifleştirildi. Artık aradığınız kriterlere göre futbolcu bulabilir, paylaşımlara yorum yapabilir ve beğenebilirsiniz.");

            return(View("Ok", okNotifyObj));
        }
コード例 #3
0
        public async Task <IActionResult> Login(LoginVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View("Login", model));
                }

                var result = await _membershipTools.SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, true);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Account"));
                }

                ModelState.AddModelError(String.Empty, "Kullanıcı adı veya şifre hatalı");
                return(View(model));
            }
            catch (Exception ex)
            {
                var errorVM = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "Index",
                    ControllerName = "Account",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM);
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #4
0
        public async Task <ActionResult> AssignedIssues()
        {
            try
            {
                var user = await _membershipTools.UserManager.GetUserAsync(HttpContext.User);

                var id   = user.Id;
                var data = _issueRepo.GetAll(x => x.OperatorId == id && x.TechnicianId == null).Select(x => Mapper.Map <IssueVM>(x)).ToList();
                if (data != null)
                {
                    return(View(data));
                }
            }
            catch (Exception ex)
            {
                var errorVM = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "AssignedIssues",
                    ControllerName = "Operator",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM);
                return(RedirectToAction("Error500", "Home"));
            }
            return(View());
        }
コード例 #5
0
 public IActionResult Index()
 {
     try
     {
         var data = _issueRepo.GetAll(x => x.OperatorId == null)
                    .Select(x => Mapper.Map <IssueVM>(x)).ToList();
         if (data != null)
         {
             return(View(data));
         }
     }
     catch (Exception ex)
     {
         var errorVM = new ErrorVM()
         {
             Text           = $"Bir hata oluştu {ex.Message}",
             ActionName     = "Index",
             ControllerName = "Operator",
             ErrorCode      = "500"
         };
         TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM);
         return(RedirectToAction("Error500", "Home"));
     }
     return(View());
 }
コード例 #6
0
 public IActionResult Index()
 {
     try
     {
         var id   = _membershipTools.UserManager.GetUserId(HttpContext.User);
         var data = _issueRepo.GetAll(x => x.TechnicianId == id && x.IssueState != IssueStates.Tamamlandı).Select(x => Mapper.Map <IssueVM>(x)).ToList();
         if (data != null)
         {
             return(View(data));
         }
     }
     catch (Exception ex)
     {
         var errorVM = new ErrorVM()
         {
             Text           = $"Bir hata oluştu. {ex.Message}",
             ActionName     = "Index",
             ControllerName = "Technician",
             ErrorCode      = "500"
         };
         TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM);
         return(RedirectToAction("Error500", "Home"));
     }
     return(View());
 }
コード例 #7
0
        public ActionResult UserProfile()
        {
            try
            {
                var id   = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();
                var user = NewUserManager().FindById(id);
                var data = new UserProfileVM()
                {
                    Email       = user.Email,
                    Id          = user.Id,
                    Name        = user.Name,
                    PhoneNumber = user.PhoneNumber,
                    Surname     = user.Surname,
                    UserName    = user.UserName,
                    AvatarPath  = string.IsNullOrEmpty(user.AvatarPath) ? "/assets/images/icon-noprofile.png" : user.AvatarPath,
                    Location    = user.Location
                };

                return(View(data));
            }
            catch (Exception ex)
            {
                TempData["Message"] = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "UserProfile",
                    ControllerName = "Account",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #8
0
        public ActionResult FootballerActivate(Guid id)
        {
            BusinessLayerResult <User> res = userManager.ActivateUser(id);

            if (res.Errors.Count > 0)
            {
                ErrorVM errorNotifyObj = new ErrorVM()
                {
                    Title = "Geçersiz İşlem",
                    Items = res.Errors
                };

                return(View("Error", errorNotifyObj));
            }

            OkVM okNotifyObj = new OkVM()
            {
                Title          = "Hesap Aktifleştirildi",
                RedirectingUrl = "/Home/FootballerLogin"
            };

            okNotifyObj.Items.Add("Hesabınız aktifleştirildi. Artık paylaşım yapabilirsiniz.");

            return(View("Ok", okNotifyObj));
        }
コード例 #9
0
        public ActionResult EditManagerProfile(Manager manager, HttpPostedFileBase ProfileImage)
        {
            if (ModelState.IsValid)
            {
                if (ProfileImage != null &&
                    (ProfileImage.ContentType == "image/jpeg" ||
                     ProfileImage.ContentType == "image/jpg" ||
                     ProfileImage.ContentType == "image/png"))
                {
                    string filename = $"manager_{manager.Id}.{ProfileImage.ContentType.Split('/')[1]}";

                    ProfileImage.SaveAs(Server.MapPath($"~/images/{filename}"));
                    manager.ProfileImageFileName = filename;
                }
                BusinessLayerResult <Manager> res = managerm.UpdateManagerProfile(manager);

                if (res.Errors.Count > 0)
                {
                    ErrorVM errorNotifyObj = new ErrorVM()
                    {
                        Items          = res.Errors,
                        Title          = "Profil Güncellenemedi",
                        RedirectingUrl = "/Home/ManagerProfileInformations",
                    };
                    return(View("Error", errorNotifyObj));
                }
                //Profil güncellendiği için Session güncellendi..
                CurrentSession.Set <Manager>("loginm", res.Result);
                return(RedirectToAction("ManagerProfileInformations"));
            }
            return(View(manager));
        }
        public static void  ConfigureBuildInExceptionHandler(this IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            app.UseExceptionHandler(appError =>
            {
                appError.Run(async context =>
                {
                    var logger = loggerFactory.CreateLogger("ConfigureBuildInExceptionHanlder");


                    context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                    context.Response.ContentType = "application/json";

                    var contextFeature = context.Features.Get <IExceptionHandlerFeature>();
                    var contextRequest = context.Features.Get <IHttpRequestFeature>();

                    if (contextFeature != null)
                    {
                        var errorVMString = new ErrorVM()
                        {
                            StatusCode = context.Response.StatusCode,
                            Message    = contextFeature.Error.Message,
                            Path       = contextRequest.Path
                        }.ToString();

                        logger.LogError(errorVMString);

                        await context.Response.WriteAsync(errorVMString);
                    }
                });
            });
        }
コード例 #11
0
        public IActionResult StatusCodePagesHandler(int code)
        {
            var     feature = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();
            ErrorVM error   = new ErrorVM();

            error.StatusCode = code;
            string message = null;

            switch (error.StatusCode)
            {
            case 400:
                message = $"Url: {feature?.OriginalPath}";
                break;

            case 404:
                message = $"Resource {feature?.OriginalPath}  NOT found";
                break;

            case 500:
                message = $"An exception occured while processing your request at {feature?.OriginalPath}. The support team is notified";
                break;
            }

            error.Message = message;
            return(View("Error", error));
        }
コード例 #12
0
        public ActionResult Survey(string code)
        {
            try
            {
                var surveyRepo = new SurveyRepo();
                var survey     = surveyRepo.GetById(code);
                if (survey.IsDone == true)
                {
                    TempData["Message2"] = "Bu anket zaten tamamlanmış.";
                    return(RedirectToAction("Index", "Home"));
                }
                if (survey == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                var data = Mapper.Map <Survey, SurveyVM>(survey);
                return(View(data));
            }
            catch (Exception ex)
            {
                TempData["Message2"] = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "Survey",
                    ControllerName = "Issue",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #13
0
        public async Task <ActionResult> UserProfile()
        {
            try
            {
                var user = await _membershipTools.UserManager.GetUserAsync(HttpContext.User);

                var data = new UserProfileVM()
                {
                    Email       = user.Email,
                    Id          = user.Id,
                    Name        = user.Name,
                    PhoneNumber = user.PhoneNumber,
                    Surname     = user.Surname,
                    UserName    = user.UserName,
                    AvatarPath  = string.IsNullOrEmpty(user.AvatarPath) ? "/assets/images/icon-noprofile.png" : user.AvatarPath,
                    Latitude    = user.Latitude,
                    Longitude   = user.Longitude
                };

                return(View(data));
            }
            catch (Exception ex)
            {
                var errorVM = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "UserProfile",
                    ControllerName = "Account",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM);
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #14
0
        public ActionResult Reports()
        {
            try
            {
                var issueRepo  = _issueRepo;
                var surveyRepo = _surveyRepo;
                var issueList  = issueRepo.GetAll(x => x.SurveyId != null).ToList();

                var surveyList        = surveyRepo.GetAll().Where(x => x.IsDone).ToList();
                var totalSpeed        = 0.0;
                var totalTech         = 0.0;
                var totalPrice        = 0.0;
                var totalSatisfaction = 0.0;
                var totalSolving      = 0.0;
                var count             = issueList.Count;

                if (count == 0)
                {
                    TempData["Message2"] = "Rapor oluşturmak için yeterli kayıt bulunamadı.";
                    return(RedirectToAction("Index", "Home"));
                }

                foreach (var survey in surveyList)
                {
                    totalSpeed        += survey.Speed;
                    totalTech         += survey.TechPoint;
                    totalPrice        += survey.Pricing;
                    totalSatisfaction += survey.Satisfaction;
                    totalSolving      += survey.Solving;
                }

                var totalDays = 0;
                foreach (var issue in issueList)
                {
                    totalDays += issue.ClosedDate.Value.DayOfYear - issue.CreatedDate.DayOfYear;
                }

                ViewBag.AvgSpeed        = totalSpeed / count;
                ViewBag.AvgTech         = totalTech / count;
                ViewBag.AvgPrice        = totalPrice / count;
                ViewBag.AvgSatisfaction = totalSatisfaction / count;
                ViewBag.AvgSolving      = totalSolving / count;
                ViewBag.AvgTime         = totalDays / issueList.Count;

                return(View(surveyList));
            }
            catch (Exception ex)
            {
                var errorVM = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "Reports",
                    ControllerName = "Admin",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM);
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #15
0
        public async Task <ActionResult> FinishJob(IssueVM model)
        {
            try
            {
                var issueRepo = new IssueRepo();
                var issue     = issueRepo.GetById(model.IssueId);
                if (issue == null)
                {
                    TempData["Message2"] = "Arıza kaydı bulunamadi.";
                    return(RedirectToAction("Index", "Technician"));
                }

                issue.IssueState = IssueStates.Tamamlandı;
                issue.ClosedDate = DateTime.Now;
                issueRepo.Update(issue);
                TempData["Message"] = $"{issue.Description} adlı iş tamamlandı.";

                var survey     = new Survey();
                var surveyRepo = new SurveyRepo();
                surveyRepo.Insert(survey);
                issue.SurveyId = survey.Id;
                issueRepo.Update(issue);

                var user = await NewUserStore().FindByIdAsync(issue.CustomerId);

                var usernamesurname = GetNameSurname(issue.CustomerId);

                string siteUrl = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host +
                                 (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port);

                var emailService = new EmailService();
                var body         = $"Merhaba <b>{usernamesurname}</b><br>{issue.Description} adlı arıza kaydınız kapanmıştır.<br>Değerlendirmeniz için aşağıda linki bulunan anketi doldurmanızı rica ederiz.<br> <a href='{siteUrl}/issue/survey?code={issue.SurveyId}' >Anket Linki </a> ";
                await emailService.SendAsync(new IdentityMessage()
                {
                    Body = body, Subject = "Değerlendirme Anketi"
                }, user.Email);

                var issueLog = new IssueLog()
                {
                    IssueId     = issue.Id,
                    Description = "İş tamamlandı.",
                    FromWhom    = "Teknisyen"
                };
                new IssueLogRepo().Insert(issueLog);

                return(RedirectToAction("Index", "Technician"));
            }
            catch (Exception ex)
            {
                TempData["Message"] = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu. {ex.Message}",
                    ActionName     = "FinishJob",
                    ControllerName = "Technician",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #16
0
        public async Task <ActionResult> ChangePassword(ChangePasswordVM model)
        {
            try
            {
                var userManager = NewUserManager();
                var id          = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();
                var user        = NewUserManager().FindById(id);

                var data = new ChangePasswordVM()
                {
                    OldPassword        = model.OldPassword,
                    NewPassword        = model.NewPassword,
                    ConfirmNewPassword = model.ConfirmNewPassword
                };

                model = data;
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                var result = await userManager.ChangePasswordAsync(
                    HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId(),
                    model.OldPassword, model.NewPassword);

                if (result.Succeeded)
                {
                    var emailService = new EmailService();
                    var body         = $"Merhaba <b>{user.Name} {user.Surname}</b><br>Hesabınızın şifresi değiştirilmiştir. <br> Bilginiz dahilinde olmayan değişiklikler için hesabınızı güvence altına almanızı öneririz.</p>";
                    emailService.Send(new IdentityMessage()
                    {
                        Body = body, Subject = "Şifre Değiştirme hk."
                    }, user.Email);

                    return(RedirectToAction("Logout", "Account"));
                }
                else
                {
                    var err = "";
                    foreach (var resultError in result.Errors)
                    {
                        err += resultError + " ";
                    }
                    ModelState.AddModelError("", err);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (Exception ex)
            {
                TempData["Message"] = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "ChangePassword",
                    ControllerName = "Account",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #17
0
        public IActionResult Index()
        {
            ErrorVM errorVM = new ErrorVM();

            errorVM.Users   = errorRepository.GetUsers();
            errorVM.Tickets = errorRepository.GetTickets();
            return(View(errorVM));
        }
コード例 #18
0
ファイル: EntityExtensions.cs プロジェクト: tckhanh/Vilas103
 public static void UpdateError(this Error item, ErrorVM itemVM)
 {
     item.Message     = itemVM.Message;
     item.Description = itemVM.Description;
     item.Controller  = itemVM.Controller;
     item.StackTrace  = itemVM.StackTrace;
     item.CreatedDate = itemVM.CreatedDate;
 }
コード例 #19
0
        public async Task <ActionResult> RecoverPassword(RecoverPasswordVM model)
        {
            try
            {
                var userStore   = _membershipTools.NewUserStore();
                var userManager = _membershipTools.UserManager;

                var user = await userStore.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, $"{model.Email} mail adresine kayıtlı bir üyeliğe erişilemedi");
                    return(View(model));
                }

                var newPassword  = StringHelpers.GetCode().Substring(0, 6) + "A0*";
                var hashPassword = userManager.PasswordHasher.HashPassword(user, newPassword);

                await userStore.SetPasswordHashAsync(user, hashPassword);

                var result = userStore.Context.SaveChanges();

                if (result == 0)
                {
                    var errorVM = new ErrorVM()
                    {
                        Text           = $"Bir hata oluştu",
                        ActionName     = "RecoverPassword",
                        ControllerName = "Account",
                        ErrorCode      = "500"
                    };
                    TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM);
                    return(RedirectToAction("Error500", "Home"));
                }

                var emailService = new EmailService();
                var body         = $"Merhaba <b>{user.Name} {user.Surname}</b><br>Hesabınızın parolası sıfırlanmıştır<br> Yeni parolanız: <b>{newPassword}</b> <p>Yukarıdaki parolayı kullanarak sitemize giriş yapabilirsiniz.</p>";
                emailService.Send(new EmailModel()
                {
                    Body = body, Subject = $"{user.UserName} Şifre Kurtarma"
                }, user.Email);
            }

            catch (Exception ex)
            {
                var errorVM = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "RecoverPassword",
                    ControllerName = "Account",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM);
                return(RedirectToAction("Error500", "Home"));
            }
            TempData["Message"] = $"{model.Email} mail adresine yeni şifre gönderildi.";
            return(View());
        }
コード例 #20
0
        public async Task <ActionResult> AssignTechAsync(IssueVM model)
        {
            try
            {
                var issue = new IssueRepo().GetById(model.IssueId);
                issue.TechnicianId = model.TechnicianId;
                issue.IssueState   = Models.Enums.IssueStates.Atandı;
                issue.OptReport    = model.OptReport;
                new IssueRepo().Update(issue);
                var technician = await NewUserStore().FindByIdAsync(issue.TechnicianId);

                TempData["Message"] =
                    $"{issue.Description} adlı arızaya {technician.Name}  {technician.Surname} teknisyeni atandı.";

                var customer     = NewUserManager().FindById(issue.CustomerId);
                var emailService = new EmailService();
                var body         = $"Merhaba <b>{GetNameSurname(issue.CustomerId)}</b><br>{issue.Description} adlı arızanız onaylanmıştır ve görevli teknisyen en kısa sürede yola çıkacaktır.";
                await emailService.SendAsync(new IdentityMessage()
                {
                    Body    = body,
                    Subject = $"{issue.Description} adlı arıza hk."
                }, customer.Email);

                var issueLog = new IssueLog()
                {
                    IssueId     = issue.Id,
                    Description = "Teknisyene atandı.",
                    FromWhom    = "Operatör"
                };
                new IssueLogRepo().Insert(issueLog);

                return(RedirectToAction("AllIssues", "Operator"));
            }
            catch (DbEntityValidationException ex)
            {
                TempData["Message"] = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu: {EntityHelpers.ValidationMessage(ex)}",
                    ActionName     = "AssignTechAsync",
                    ControllerName = "Operator",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error500", "Home"));
            }
            catch (Exception ex)
            {
                TempData["Message"] = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "AssignTechAsync",
                    ControllerName = "Operator",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #21
0
        public IActionResult ExceptionHandler()
        {
            ErrorVM error   = new ErrorVM();
            var     feature = HttpContext.Features.Get <IExceptionHandlerPathFeature>();

            error.StatusCode = HttpContext.Response.StatusCode;
            error.Message    = $"An exception occured while processing your request at {feature?.Path}. The support team is notified";
            _logger.LogError(feature.Error.GetType().Name);
            return(View("Error", error));
        }
コード例 #22
0
        public async Task <IActionResult> Create(ItemCreateIM model)
        {
            if (ModelState.IsValid == false)
            {
                return(View(model));
            }

            ItemType itemType;
            bool     isValidType = Enum.TryParse <ItemType>(model.Type, out itemType);

            CommercialType itemCommType;
            bool           isValidCommercialType = Enum.TryParse <CommercialType>(model.CommercialType, out itemCommType);

            Sizing size;
            bool   isValidSize = Enum.TryParse <Sizing>(model.Size, out size);

            if (isValidCommercialType == false ||
                isValidType == false ||
                isValidSize == false)
            {
                var error = new ErrorVM
                {
                    Message = "Please, insert Personal, Gift or ForSale as Commercial Type"
                };

                return(RedirectToAction("Error", error));
            }

            var createSM = new ItemCreateSM
            {
                Title          = model.Title,
                Description    = model.Description,
                Type           = itemType,
                CommercialType = itemCommType,
                Size           = size,
                Price          = model.Price,
                Quantity       = model.Quantity
            };

            createSM.ImageUrls = await UploadImages((List <IFormFile>) model.Images, model.Title);

            var createResult = await this.itemService.CreateAsync(createSM);

            if (createResult == null)
            {
                var error = new ErrorVM
                {
                    Message = "The item was not properly added to the Database."
                };

                return(RedirectToAction("Error", error));
            }

            return(Redirect("/"));
        }
コード例 #23
0
        // note: user role cannot access deactive app
        public static ICollection <ApplicationVM> queryAllAppErrsByPsersonId(int id)
        {
            ICollection <ApplicationVM> appVMs = new List <ApplicationVM>();

            using (DatabaseModel.ErrorModelDbContext db = new DatabaseModel.ErrorModelDbContext())
            {
                // Initialize the DB - false doesn't force reinitialization if the DB already exists
                db.Database.Initialize(false);

                var queryUserRole = (from n in db.LoginSet where n.OnePerson.PersonId == id select n).First().Role;

                List <Application> queryApps;
                // check whether user-role, if yes, filter deactive apps
                if (queryUserRole < (int)RoleEnum.Admin)
                {
                    queryApps = (from n in db.ApplicationSet
                                 where n.Persons.Any(x => x.PersonId == id) && n.IsActive == true
                                 select n).ToList();
                }
                else
                {
                    queryApps = (from n in db.ApplicationSet
                                 where n.Persons.Any(x => x.PersonId == id)
                                 select n).ToList();
                }

                foreach (var app in queryApps)
                {
                    var appVM = new ApplicationVM()
                    {
                        ApplicationId = app.ApplicationId,
                        AppName       = app.AppName,
                        IsActive      = app.IsActive
                    };

                    foreach (var err in app.Errors)
                    {
                        var errVm = new ErrorVM()
                        {
                            ErrorId      = err.ErrorId,
                            ErrorMessage = err.ErrorMessage,
                            Time         = err.Time,
                            LogLevel     = err.LogLevel,
                            ExMessage    = err.ExMessage
                        };
                        appVM.Errors.Add(errVm);
                    }

                    appVMs.Add(appVM);
                }
            }

            return(appVMs);
        }
コード例 #24
0
        public async Task <ActionResult> EditUser(string id)
        {
            try
            {
                var userManager = _membershipTools.UserManager;
                var user        = await userManager.FindByIdAsync(id);

                if (user == null)
                {
                    return(RedirectToAction("Index"));
                }

                var roles = await userManager.GetRolesAsync(user);

                var roller = GetRoleList();
                foreach (var role in roles)
                {
                    foreach (var selectListItem in roller)
                    {
                        if (selectListItem.Value == role)
                        {
                            selectListItem.Selected = true;
                        }
                    }
                }

                ViewBag.RoleList = roller;
                var model = Mapper.Map <ApplicationUser, UserProfileVM>(user);
                //var model = new UserProfileVM()
                //{
                //    AvatarPath = user.AvatarPath,
                //    Name = user.Name,
                //    Email = user.Email,
                //    Surname = user.Surname,
                //    Id = user.Id,
                //    PhoneNumber = user.PhoneNumber,
                //    UserName = user.UserName
                //};
                return(View(model));
            }
            catch (Exception ex)
            {
                var errorVM = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "EditUser",
                    ControllerName = "Admin",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM);
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #25
0
        public IActionResult Error()
        {
            var errorVM = new ErrorVM();

            errorVM.ErrorMessage = HttpContext.Session.GetString("error");
            if (User.Identity.Name != null)
            {
                AgonManager.LogError(new LogError(User.Identity.Name, DateTime.Now, errorVM.ErrorMessage));
            }

            return(View(errorVM));
        }
コード例 #26
0
        private Task HandleExceptionAsync(HttpContext httpContext, Exception ex)
        {
            httpContext.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
            httpContext.Response.ContentType = "application/json";

            var response = new ErrorVM()
            {
                StatusCode = httpContext.Response.StatusCode,
                Message    = "Internal Server Error from custom middleware",
                Path       = "path-goes-here"
            };

            return(httpContext.Response.WriteAsync(response.ToString()));
        }
コード例 #27
0
        private static async Task UnauthorisedAccess(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            context.Response.StatusCode  = (int)HttpStatusCode.Unauthorized;
            var error = new ErrorVM
            {
                Message = "You are not authorised. Please log in or sign up first."
            };

            var jsonString = JsonConvert.SerializeObject(error, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });
            await context.Response.WriteAsync(jsonString);
        }
コード例 #28
0
        private async Task AccessDenied(HttpContext context, string message)
        {
            context.Response.ContentType = "application/json";
            context.Response.StatusCode  = (int)HttpStatusCode.Unauthorized;
            var error = new ErrorVM
            {
                Message = message
            };

            var jsonString = JsonConvert.SerializeObject(error, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });
            await context.Response.WriteAsync(jsonString);
        }
コード例 #29
0
        public ActionResult EditUser(string id)
        {
            try
            {
                var user = NewUserManager().FindById(id);
                if (user == null)
                {
                    return(RedirectToAction("Index"));
                }

                var roller = GetRoleList();
                foreach (var role in user.Roles)
                {
                    foreach (var selectListItem in roller)
                    {
                        if (selectListItem.Value == role.RoleId)
                        {
                            selectListItem.Selected = true;
                        }
                    }
                }

                ViewBag.RoleList = roller;


                var model = new UserProfileVM()
                {
                    AvatarPath  = user.AvatarPath,
                    Name        = user.Name,
                    Email       = user.Email,
                    Surname     = user.Surname,
                    Id          = user.Id,
                    PhoneNumber = user.PhoneNumber,
                    UserName    = user.UserName
                };
                return(View(model));
            }
            catch (Exception ex)
            {
                TempData["Message"] = new ErrorVM()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "EditUser",
                    ControllerName = "Admin",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error500", "Home"));
            }
        }
コード例 #30
0
        public ActionResult FootballerProfileInformations()
        {
            BusinessLayerResult <Footballer> res = footballerManager.GetFootballerById(CurrentSession.footballer.Id);

            if (res.Errors.Count > 0)
            {
                ErrorVM errorNotifyObj = new ErrorVM()
                {
                    Title = "Hata Oluştu",
                    Items = res.Errors
                };
                return(View("Error", errorNotifyObj));
            }
            return(View(res.Result));
        }