private void RunMigrations() { if (!ApplicationEnv.GetBoolConfiguration(Constants.USE_MEMORY_DB)) { ApplicationContext ctx = Activator.CreateInstance <ApplicationContext>(); ctx.Database.Migrate(); } }
private string GetNewCode() { int length = ApplicationEnv.GetIntConfiguration(Constants.SHORT_URL_CODE_LENGTH); string code = TokenUtils.GenerateCode(length); while (DataAccess.GetByCode(code) != null) { code = TokenUtils.GenerateCode(length); } return(code); }
public ActionResult GetLast(long userId) { try { string host = ApplicationEnv.GetApiUrl(HttpContext); return(Ok(ShortUrlBusiness.GetLastByIdUser(userId).Select(x => new ShortUrlDTO(x, host)))); } catch (ShortUrlException e) { return(BadRequest(e.Message)); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); services.AddHttpContextAccessor(); services.AddDbContext <ApplicationContext>(); services.AddScoped <CustomerService>(); services.AddScoped <GroupClassService>(); services.AddScoped <InstructorService>(); services.AddScoped <PaymentService>(); services.AddScoped <PhysicalEvaluationService>(); services.AddScoped <PresenceService>(); services.AddScoped <UserService>(); services.AddScoped <VacationService>(); services.AddScoped <MockService>(); services.AddScoped <CustomerDataAccess>(); services.AddScoped <GroupClassDataAccess>(); services.AddScoped <InstructorDataAccess>(); services.AddScoped <PaymentDataAccess>(); services.AddScoped <PhysicalEvaluationDataAccess>(); services.AddScoped <PresenceDataAccess>(); services.AddScoped <UserDataAccess>(); services.AddScoped <VacationDataAccess>(); AuthorizationProvider.Configure(services); ApplicationEnv.ServiceProvider = services.BuildServiceProvider(); if (ApplicationEnv.GetBoolConfiguration(Constants.RUN_MIGRATIONS) && !ApplicationEnv.GetBoolConfiguration(Constants.USE_MEMORY_DB)) { ((ApplicationContext)Activator.CreateInstance(typeof(ApplicationContext))).Database.Migrate(); } MockService mockService = ApplicationEnv.ServiceProvider.GetService <MockService>(); mockService.AdminUser(); if (ApplicationEnv.GetBoolConfiguration(Constants.RUN_START_TASK)) { mockService.Mock(); } }
public ActionResult GetStats(string code) { try { string host = ApplicationEnv.GetApiUrl(HttpContext); ShortUrl url = ShortUrlBusiness.Stats(code); var dto = new ShortUrlDTO(url, host, fullData: true); dto.countClick = ClickBusiness.CountClicksByCode(code); return(Ok(dto)); } catch (ShortUrlException e) { return(BadRequest(e.Message)); } }
public ActionResult Post([FromBody] SaveShortUrlRequestDTO payload) { try { ShortUrl shortUrl = ShortUrlBusiness.MakeShortUrl(payload.url, payload.userId); ShortUrlDTO dto = new ShortUrlDTO(shortUrl, ApplicationEnv.GetApiUrl(HttpContext)); return(Ok(dto)); } catch (InvalidUrlException e) { e.Ship(); return(StatusCode((int)HttpStatusCode.NotAcceptable)); } catch (ShortUrlException e) { return(BadRequest(e.Message)); } }
public ActionResult Get(string code) { try { ShortUrl url = ShortUrlBusiness.Clicked(code, ApplicationEnv.GetClientIP(HttpContext)); return(Redirect(url.Original)); } catch (ShortUrlException e) { e.Ship(); string redirect = ApplicationEnv.GetStringConfiguration(Constants.NOT_FOUND_REDIRECT_URL); if (ApplicationEnv.GetBoolConfiguration(Constants.NOT_FOUND_REDIRECT_INCLUDE_CODE)) { redirect += "/" + code; } return(Redirect(redirect)); } }
public ActionResult Get() { User user = UserBusiness.RequestNewUser(ApplicationEnv.GetClientIP(HttpContext)); return(Ok(new UserDTO(user))); }
public override ActionResult Get() { User user = Service.GetById(ApplicationEnv.GetUserIdentification().Id); return(Ok(new UserDto(user))); }