Quantcast
Channel: ASP.NET Core
Viewing all 9386 articles
Browse latest View live

Check if image exists on the frontend razor page

$
0
0

hi guys

how do i check if an image exists on my frontend razor page ? (in yellow below)

I can easily check on the server side, but I want this code done on the client side

As my images are dynamically loaded from the database

Here is my code

  @for (i = i + 1; i < Model.Count(); i++)
                        {

                                  image = (Model[i].Category_Name).Trim();
                        image = image.Replace(" ", "_");
                         image = image.Replace(".", "_");
                         image = image.Replace(":", "_");
                        image = image + ".png";<div class="col-md-4 text-center div_for_col4   classify"><a href="Categories/ "><h3>
                                        @Model[i].Category_Name<br /></h3><span><img src="~/images/Department_Categories/templates/@image2/@image" alt="@(Model[i].Category_Name)" width="200" class="img-fluid" /><br /><br />@Model[i].Description_Short</span><br /><br /></a><hr class="horizontal-rule-blue" /></div>


                        }

REACT REDUX UI and Data Issue

$
0
0

Hi,

I have created an asp.net MVC core 3.0 application with react REDUX.

I am trying to create an example.

 I am trying to create cards with data and want to share the code.  

I think my source should be more improved (like async/await and other approaches).

 I am displaying cards but UI doesn't seems to be accurate. can someone suggest a better fix to me ?

-- product.ts ---------------

import { Action, Reducer } from 'redux';
import { AppThunkAction } from '.';

// -----------------
// STATE - This defines the type of data maintained in the Redux store.

export interface ProductState {
    isLoading: boolean;
    startDateIndex?: number;
    products: Product[];
}

export interface Product {
    Id: number;
    Date: string;
    Code: number;
    Name: string;
    Price: number;
    Description: string;
}

// -----------------
// ACTIONS - These are serializable (hence replayable) descriptions of state transitions.
// They do not themselves have any side-effects; they just describe something that is going to happen.

interface RequestProductsAction {
    type: 'REQUEST_PRODUCTS';
    startDateIndex: number;
}

interface ReceiveProductsAction {
    type: 'RECEIVE_PRODUCTS';
    startDateIndex: number;
    products: Product[];
}

// Declare a 'discriminated union' type. This guarantees that all references to 'type' properties contain one of the
// declared type strings (and not any other arbitrary string).
type KnownAction = RequestProductsAction | ReceiveProductsAction;

// ----------------
// ACTION CREATORS - These are functions exposed to UI components that will trigger a state transition.
// They don't directly mutate state, but they can have external side-effects (such as loading data).

export const actionCreators = {
    requestProducts: (startDateIndex: number): AppThunkAction<KnownAction> => (dispatch, getState) => {
        //debugger;
        // Only load data if it's something we don't already have (and are not already loading)
        const appState = getState();
        if (appState && appState.products && startDateIndex !== appState.products.startDateIndex) {
            fetch(`products`)
                .then(response => response.json() as Promise<Product[]>)
                .then(data => {
                    dispatch({ type: 'RECEIVE_PRODUCTS', startDateIndex: startDateIndex, products: data });
                });

            dispatch({ type: 'REQUEST_PRODUCTS', startDateIndex: startDateIndex });
        }
    }
};

// ----------------
// REDUCER - For a given state and action, returns the new state. To support time travel, this must not mutate the old state.

const unloadedState: ProductState = { products:[], isLoading: false };

export const reducer: Reducer<ProductState> = (state: ProductState | undefined, incomingAction: Action): ProductState => {
    //debugger;
    if (state === undefined) {
        return unloadedState;
    }

    const action = incomingAction as KnownAction;
    switch (action.type) {
        case 'REQUEST_PRODUCTS':
            return {
                startDateIndex: action.startDateIndex,
                products: state.products,
                isLoading: true
            };
        case 'RECEIVE_PRODUCTS':
            // Only accept the incoming data if it matches the most recent request. This ensures we correctly
            // handle out-of-order responses.
            if (action.startDateIndex === state.startDateIndex) {
                return {
                    startDateIndex: action.startDateIndex,
                    products: action.products,
                    isLoading: false
                };
            }
            break;
    }

    return state;
};


--------------Home.tsx-------------------------------

import * as React from 'react';
import { connect } from 'react-redux';
import { RouteComponentProps } from 'react-router';
import { Link } from 'react-router-dom';
import { ApplicationState } from '../store';
import * as logoImg from "../images/191d14327e6facffb4cefb2d8e7ff2ce.jpg";
const mystyles = {
    width: '18rem',
} as React.CSSProperties;

import * as ProductStateStore from '../store/Product';

// At runtime, Redux will merge together...
type ProductProps =
    ProductStateStore.ProductState // ... state we've requested from the Redux store
    & typeof ProductStateStore.actionCreators // ... plus action creators we've requested& RouteComponentProps<{ startDateIndex: string }>; // ... plus incoming routing parameters


class Home extends React.PureComponent<ProductProps> {
    // This method is called when the component is first added to the document
    public componentDidMount() {
        this.ensureDataFetched();
    }

    // This method is called when the route parameters change
    public componentDidUpdate() {
        this.ensureDataFetched();
    }

    public render() {
        return (
            <React.Fragment><h1>Weather forecast</h1><p>This component demonstrates fetching data from the server and working with URL parameters.</p>
                {this.renderProducts()}
                {/*this.renderPagination()*/}</React.Fragment>
        );
    }

    private ensureDataFetched() {
        const startDateIndex = parseInt(this.props.match.params.startDateIndex, 10) || 0;
        this.props.requestProducts(startDateIndex);
    }

    private renderProducts() {
        return (
            <React.Fragment>
                {
                    this.props.products.map((prod: ProductStateStore.Product) =><div id={String(prod.Id)} className="card" style={{ width: '18rem' }} ><img src={String(logoImg)} className="card-img-top" alt="Card image cap" /><div className="card-body"><h5 className="card-title">{prod.Name}</h5><p className="card-text">{prod.Description}.</p><p className="card-text">US${prod.Price} / Piece <br />
                            2 Pieces (Min Order)<br />
                            3 buyers </p><a href="#" className="btn btn-primary">Add To Cart</a></div></div>
                )}</React.Fragment>
        );
    }

    private renderPagination() {
        const prevStartDateIndex = (this.props.startDateIndex || 0) - 5;
        const nextStartDateIndex = (this.props.startDateIndex || 0) + 5;

        return (
            <div className="d-flex justify-content-between"><Link className='btn btn-outline-secondary btn-sm' to={`/fetch-data/${prevStartDateIndex}`}>Previous</Link>
                {this.props.isLoading && <span>Loading...</span>}<Link className='btn btn-outline-secondary btn-sm' to={`/fetch-data/${nextStartDateIndex}`}>Next</Link></div>
        );
    }
}

export default connect(
    (state: ApplicationState) => state.products, // Selects which state properties are merged into the component's props
    ProductStateStore.actionCreators // Selects which action creators are merged into the component's props
) (Home as any);
------------- ProductsController----------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace WebApplication6.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class ProductsController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<ProductsController> _logger;

        public ProductsController(ILogger<ProductsController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public IEnumerable<Product> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new Product
            {
                Id = rng.Next(1, 155),
                Date = DateTime.Now.AddDays(index),
                Code = "CEDE"+ rng.Next(-20, 55),
                Price = 56,
                Name = "Apple",
                Description = "This is a apple."
            })
            .ToArray();
        }
    }
}

----------------------------Product.cs---------------------------------------

public class Product
{
public int Id { get; set; }
public DateTime Date { set; get; }
public string Code { set; get; }
public string Name { set; get; }
public decimal Price { get; set; }
public string Description { get; set; }
}
----------------App.tsx-----------------------------

import * as React from 'react';
import { Route } from 'react-router';
import Layout from './components/Layout';
import Home from './components/Home';
import Counter from './components/Counter';
import FetchData from './components/FetchData';

export default () => (<Layout><Route exact path='/home' component={Home}/><Route path='/counter' component={Counter} /><Route path='/fetch-data/:startDateIndex?' component={FetchData} /></Layout>
);

DateTime.Now issue

$
0
0

Trying to format date so it looks like this:

08/15/2019 4:22:15.802 PM and I'm trying to format it like this 08/15/2019 04:22 PM

In the controller I am calling:

        [HttpGet]
        public IActionResult Create()
        {

            var CreateViewModel = new CreateEditViewModel();
            CreateViewModel.AsOf = DateTime.Now;
           
            return View(CreateViewModel);
        }

The property in the model is setup as:

[Required]
        [DisplayName("AsOf")]
        public DateTime? AsOf { get; set; }

What do I need to format it like I want it to?

ASP.NET Core Web Hosting Options

$
0
0

Hello,

From reading the ASP.NET Core documentation, it seems that there are a few different options for hosting a web service (I'm ignoring apache and nginx for the scope of this question).

  1. Kestrel as internet facing web server
  2. Out of process IIS as reverse proxy with Kestrel
  3. In process IIS using IISHttpServer
  4. HTTP.sys (if deploying to windows)

For building large production scale web applications, is there a recommendation for a specific approach? And what may be some factors in choosing one over the other, especially in terms of practicality?

Thanks!

Page pagination with model mvc Core

$
0
0

I have a view that has a model that already supplies all the chart url for each chart in a table.

<a href=@item.TradingChartUrl target="_blank">@item.Name</a>

Instead of clicking each link in the table I would like to use a pagination to do the job for me.

<div class="col-md-12"><nav aria-label="Page navigation example"><ul class="pagination"><li class="page-item"><a class="page-link" href="#">Previous</a></li><li class="page-item"><a class="page-link" href="#">1</a></li><li class="page-item"><a class="page-link" href="#">2</a></li><li class="page-item"><a class="page-link" href="#">3</a></li><li class="page-item"><a class="page-link" href="#">Next</a></li></ul></nav></div>

My thought is that when I come back from the _blank page and want to look at the next chart I have to find the last link I 

clicked on but I feel that the pagination could just give me the last and next chart?
 

How to segregate Admin and Member view after login and throughout the system usage until logout?

$
0
0

Hello Net Core mastas!

I know this sound ridiculous for one to ask this simple question here. This is my first attempt on developing projects base on Net Core. I have no experience on Net Framework before.

I'm using Identity features of Net Core where I can have Admin and Member in the system.

What I am trying to achieve is to segregate view between Admin role and Member role, this what i'm trying to do currently. This code is generated using Identity scaffold.

public async Task<IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: true);
                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");

                    var user = await _signInManager.UserManager.FindByEmailAsync(Input.Email);

                    var roless = await _signInManager.UserManager.GetRolesAsync(user);

                    //ViewData["UserInRole"] = roless[0];

                    _logger.LogInformation("User is in role ===================================> " + roless[0]);
                    _logger.LogInformation("Return Url ===================================> " + returnUrl);

                    if (roless[0] == "Admin")
                    {
                        // Return url to Admin controller
                        return RedirectToAction("Index", "Admin");
                    }
                    else if (roless[0] == "Member")
                    {
                        // Return url to Member controller
                        return RedirectToAction("Index", "Member");
                    }

                    //return LocalRedirect(returnUrl);
                }
                if (result.RequiresTwoFactor)
                {
                    return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return RedirectToPage("./Lockout");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return Page();
                }
            }

            // If we got this far, something failed, redisplay form
            return Page();
        }

Is this the correct approach? Or is there any proper approaches? 

Thanks in advance! Cheers \m/

preferable pure js files in react redux

$
0
0

Hi,

I want to use react redux with my asp.net core 3 application.

I think most preferable approach is pure functions rather than typescript.

Can anyone guide me how can i create pure function using js files rather than typescript files.

rather than ts , preferable approach is js

rather than tsx, preferable approach is js.

can anyone help me to  to start in visual studio 2019 ?

Auto sign-on with Logoff button and anonymous users

$
0
0

I'm not very knowledgeable about various forms of authentication, something I need to fix ASAP. In my application, users are automatically signed on from their Active Directory credentials, which are matched against the associated user from the application database. The application has two basic entry points - logged-in users are routed to the correct dashboard based on their user groups, and anonymous users are routed to the application page. The flow goes like this:

  1. ActionFilter middleware retrieves the HttpContext.User.Identity.Name value, which is the primary email address of the Active Directory user signed on.
  2. Since a user might have one of several emails as their email in the database, the Graph API is queried for a list of that user's emails, and checks the logged-in user's email against that list. 
  3. If the user is anonymous, they're routed to the application page. 

A request has been made to allow users to log off and back in with an alternate email address, which is easy if users are either logged in or are required to log in, but I'm not sure how to accomplish this when I need to allow anonymous users to be sent to a particular page that allows anonymous users. I suppose as part of my logoff method, I could set some value that identifies the current user as having just logged off, and load a log-in page based on that. Any suggestions? 


can i directly use bootstrap carousal image slider in my react redux typescript project (ASP.NET CORE 3.0) ?

$
0
0

hi

can i directly use bootstrap carousal image slider in my react redux typescript project (ASP.NET CORE 3.0) ?

or i 'll have to install some npm carousal package ?

Migrating MVC 5 to .net core 2.1

$
0
0

What are steps for Migrating MVC 5  application into .net core 2.1.

I have different areas and multiple project file(BAL,DAL,UI) in the  solution

Help with a scenario

$
0
0

Hello guys,

I have records in my SQL Server database for jobs. Those jobs are supposed to check some API data, do some calculations and notify the user. Since they are doing a long-running operations, I decided to use Hangfire and its scheduled recurring jobs because these jobs will be executed on each hour. When am I supposed to start their tasks/recurring jobs? Because anytime a bot can be added/removed/enabled/disabled.

  • When I add a new job from the client side, I simply call the following line in the ASP.NET Core Web API:
RecurringJob.AddOrUpdate(botName, () => DoWork(), $"0/5 * * * *", TimeZoneInfo.Local);
  • When I remove a job:
RecurringJob.RemoveIfExists(botName);
  • What about the job records that already exist in the database? When should they be enumerated from the database and their recurring jobs started?

What's the best practice in a such scenario?

getting error while using carousel in react redux (typescript)

$
0
0

Hi,

I am trying to use following sample ( taken from https://reactstrap.github.io/components/carousel/ ) and getting following errors:

Severity Code Description Project File Line Suppression State
Error TS2307 (TS) Cannot find module '../images/191d14327e6facffb4cefb2d8e7ff2ce.jpg'. WebApplication6, WebApplication6 JavaScript Content Files C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\Home.tsx 6 Active
Error TS2307 (TS) Cannot find module '../images/sliders/001_2019_24_haus_klimapraemie_sst1_31393.jpg'. WebApplication6, WebApplication6 JavaScript Content Files C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\Home.tsx 7 Active
Error TS2307 (TS) Cannot find module '../images/sliders/001_2019_26_waes_top20_strandbekleidung_32337.jpg'. WebApplication6, WebApplication6 JavaScript Content Files C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\Home.tsx 9 Active
Error TS2307 (TS) Cannot find module '../images/sliders/001_2019_30_sais_oktoberfest_flexpage_34377.jpg'. WebApplication6, WebApplication6 JavaScript Content Files C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\Home.tsx 8 Active
Error TS2304 (TS) Cannot find name 'Component'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 28 Active
Error TS7006 (TS) Parameter 'newIndex' implicitly has an 'any' type. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project) C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 59 Active
Error TS7006 (TS) Parameter 'props' implicitly has an 'any' type. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project) C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 29 Active
Error TS2339 (TS) Property 'animating' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 40 Active
Error TS2339 (TS) Property 'animating' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 44 Active
Error TS2339 (TS) Property 'animating' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 48 Active
Error TS2339 (TS) Property 'animating' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 54 Active
Error TS2339 (TS) Property 'animating' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 60 Active
Error TS2339 (TS) Property 'setState' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 50 Active
Error TS2339 (TS) Property 'setState' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 56 Active
Error TS2339 (TS) Property 'setState' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 61 Active
Error TS2339 (TS) Property 'state' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 31 Active
Error TS2339 (TS) Property 'state' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 49 Active
Error TS2339 (TS) Property 'state' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 49 Active
Error TS2339 (TS) Property 'state' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 55 Active
Error TS2339 (TS) Property 'state' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 55 Active
Error TS2339 (TS) Property 'state' does not exist on type 'Example'. C:\Users\child\Source\Repos\WebApplication6\ClientApp (tsconfig or jsconfig project), WebApplication6 C:\Users\c\Source\Repos\WebApplication6\ClientApp\src\components\CarouselComp.tsx 65 Active

import React, { Component } from 'react';
import {
  Carousel,
  CarouselItem,
  CarouselControl,
  CarouselIndicators,
  CarouselCaption
} from 'reactstrap';

const items = [
  {
    src: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22800%22%20height%3D%22400%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%20400%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_15ba800aa1d%20text%20%7B%20fill%3A%23555%3Bfont-weight%3Anormal%3Bfont-family%3AHelvetica%2C%20monospace%3Bfont-size%3A40pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_15ba800aa1d%22%3E%3Crect%20width%3D%22800%22%20height%3D%22400%22%20fill%3D%22%23777%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22285.921875%22%20y%3D%22218.3%22%3EFirst%20slide%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E',
    altText: 'Slide 1',
    caption: 'Slide 1'
  },
  {
    src: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22800%22%20height%3D%22400%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%20400%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_15ba800aa20%20text%20%7B%20fill%3A%23444%3Bfont-weight%3Anormal%3Bfont-family%3AHelvetica%2C%20monospace%3Bfont-size%3A40pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_15ba800aa20%22%3E%3Crect%20width%3D%22800%22%20height%3D%22400%22%20fill%3D%22%23666%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22247.3203125%22%20y%3D%22218.3%22%3ESecond%20slide%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E',
    altText: 'Slide 2',
    caption: 'Slide 2'
  },
  {
    src: 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22800%22%20height%3D%22400%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%20400%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_15ba800aa21%20text%20%7B%20fill%3A%23333%3Bfont-weight%3Anormal%3Bfont-family%3AHelvetica%2C%20monospace%3Bfont-size%3A40pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_15ba800aa21%22%3E%3Crect%20width%3D%22800%22%20height%3D%22400%22%20fill%3D%22%23555%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22277%22%20y%3D%22218.3%22%3EThird%20slide%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E',
    altText: 'Slide 3',
    caption: 'Slide 3'
  }
];

class Example extends Component {
  constructor(props) {
    super(props);
    this.state = { activeIndex: 0 };
    this.next = this.next.bind(this);
    this.previous = this.previous.bind(this);
    this.goToIndex = this.goToIndex.bind(this);
    this.onExiting = this.onExiting.bind(this);
    this.onExited = this.onExited.bind(this);
  }

  onExiting() {
    this.animating = true;
  }

  onExited() {
    this.animating = false;
  }

  next() {
    if (this.animating) return;
    const nextIndex = this.state.activeIndex === items.length - 1 ? 0 : this.state.activeIndex + 1;
    this.setState({ activeIndex: nextIndex });
  }

  previous() {
    if (this.animating) return;
    const nextIndex = this.state.activeIndex === 0 ? items.length - 1 : this.state.activeIndex - 1;
    this.setState({ activeIndex: nextIndex });
  }

  goToIndex(newIndex) {
    if (this.animating) return;
    this.setState({ activeIndex: newIndex });
  }

  render() {
    const { activeIndex } = this.state;

    const slides = items.map((item) => {
      return (<CarouselItem
          onExiting={this.onExiting}
          onExited={this.onExited}
          key={item.src}><img src={item.src} alt={item.altText} /><CarouselCaption captionText={item.caption} captionHeader={item.caption} /></CarouselItem>
      );
    });

    return (
      <Carousel
        activeIndex={activeIndex}
        next={this.next}
        previous={this.previous}><CarouselIndicators items={items} activeIndex={activeIndex} onClickHandler={this.goToIndex} />
        {slides}<CarouselControl direction="prev" directionText="Previous" onClickHandler={this.previous} /><CarouselControl direction="next" directionText="Next" onClickHandler={this.next} /></Carousel>
    );
  }
}


export default Example;

Lazy Button to loop through a table of links _blank

$
0
0

I have a table with rows of chart links and I click on each of the table rows, one after the other to view each _blank chart.

Check the chart and close it to click on the next table row chart, boring

Can I have a button that I click that goes to the next chart in the table row, one after the other .

How to make global variables on asp.net core 2 on level of all project web API ?

$
0
0

problem

How to make global variables on asp.net core 2 on level of all project web API ?

I work on asp.net core 2.1 project web API 

i have more controller and i need to use global variables for all solution or project shared CompanyCode value

so that how to do that on asp.net core 

so that how to make company code as global variables or session or shared if i call it in any controller i can get values ?

select one of N cards

$
0
0

I want to display N bootstrap cards, with one of them highlighted to show it was previously selected.

Then, when the user clicks on one of the cards, I want to know which card was selected on server side.

I don't know what I have done wrong, but it seems my entire approach is suspect and so I would like to start over.


[Hot Issue in July] [Reprint] Implement JsonConvert.PopulateObject in ASP.net Core 3.0

$
0
0

    ASP.net Core 3.0 provides new fast built-in JSON support, called System.Text.Json namespace. As it's not a fully replacement of Newtonsoft.Json, it not provides similar functionatily like "PopulateObject" in Newtonsoft.Json:

// in Newtonsolft.Json
JsonConvert.PopulateObject(jsonstring, obj);

// in asp.net core 3
var obj = JsonSerializer.Parse<T>(jsonstring);
var jsonstring = JsonSerializer.ToString(obj);

We can implement a static function as a workaround:

using System;
using System.Linq;
using System.Reflection;
using System.Text.Json.Serialization;

namespace ConsoleApp
{
    public class Model
    {
        public Model()
        {
            SubModel = new SubModel();
        }

        public string Title { get; set; }
        public string Head { get; set; }
        public string Link { get; set; }
        public SubModel SubModel { get; set; }
    }

    public class SubModel
    {
        public string Name { get; set; }
        public string Description { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var model = new Model();

            Console.WriteLine(JsonSerializer.ToString(model));

            var json1 = "{ \"Title\": \"Startpage\", \"Link\": \"/index\" }";

            model = Map<Model>(model, json1);

            Console.WriteLine(JsonSerializer.ToString(model));

            var json2 = "{ \"Head\": \"Latest news\", \"Link\": \"/news\", \"SubModel\": { \"Name\": \"Reyan Chougle\" } }";

            model = Map<Model>(model, json2);

            Console.WriteLine(JsonSerializer.ToString(model));

            var json3 = "{ \"Head\": \"Latest news\", \"Link\": \"/news\", \"SubModel\": { \"Description\": \"I am a Software Engineer\" } }";

            model = Map<Model>(model, json3);

            Console.WriteLine(JsonSerializer.ToString(model));

            var json4 = "{ \"Head\": \"Latest news\", \"Link\": \"/news\", \"SubModel\": { \"Description\": \"I am a Software Programmer\" } }";

            model = Map<Model>(model, json4);

            Console.WriteLine(JsonSerializer.ToString(model));

            Console.ReadKey();
        }

        public static T Map<T>(T obj, string jsonString) where T : class
        {
            var newObj = JsonSerializer.Parse<T>(jsonString);

            foreach (var property in newObj.GetType().GetProperties())
            {
                if (obj.GetType().GetProperties().Any(x => x.Name == property.Name && property.GetValue(newObj) != null))
                {
                    if (property.GetType().IsClass && property.PropertyType.Assembly.FullName == typeof(T).Assembly.FullName)
                    {
                        MethodInfo mapMethod = typeof(Program).GetMethod("Map");
                        MethodInfo genericMethod = mapMethod.MakeGenericMethod(property.GetValue(newObj).GetType());
                        var obj2 = genericMethod.Invoke(null, new object[] { property.GetValue(newObj), JsonSerializer.ToString(property.GetValue(newObj)) });

                        foreach (var property2 in obj2.GetType().GetProperties())
                        {
                            if (property2.GetValue(obj2) != null)
                            {
                                property.GetValue(obj).GetType().GetProperty(property2.Name).SetValue(property.GetValue(obj), property2.GetValue(obj2));
                            }
                        }
                    }
                    else
                    {
                        property.SetValue(obj, property.GetValue(newObj));
                    }
                }
            }

            return obj;
        }
    }
}

And the output of this program:

Please refer to the source post at Stack overflow .Net Core 3.0 JsonSerializer populate existing object, for information.

Sniff Bluetooth traffic using a dongle

$
0
0

Maybe someone could shed some light or give an example on how to access Bluetooth traffice using .NET core 3.0 on a Raspberry (or any other linux)?

Hosted Asp.net mvc core app shows list of Files instead of Home Page

$
0
0

Hello everyone, 

I've published my app into release Version in order to host it on locally IIS server, the app is published correctly and is hosted on the server, but when I open the url in the browser for the hosted app it shows me the list of files in that directory instead of my app Home page.

here's a screen shot of my problem

https://imgur.com/K4gqbql

and this is the code for my web.config file

<?xml version="1.0" encoding="UTF-8"?><configuration><system.webServer><directoryBrowse enabled="true" /><defaultDocument><files><clear /><add value="index.html" /><add value="Default.htm" /><add value="Default.asp" /><add value="index.htm" /><add value="iisstart.htm" /><add value="default.aspx" /></files></defaultDocument></system.webServer></configuration>

can you help me please 

IBM.Data.Informix with Mvc core

$
0
0

Hi
I am using IBM.Data.Informix with mvc core to connect to Informix and it is going to sleep mode when i try to connect without any exception, i am unable to connect

After it reach to this place it goes in sleep mode without responding, even not giving exception as i have try catch block

  IfxConnection conn =
                    new IfxConnection(
                     UccxConnectionString
                    );

Regards

How to connect SQL Server Object Explorer with MSSQL Server Managment Studio?

$
0
0

Hello Net Core mastas!

I have managed to develop .Net Core MVC which utilizing EF Core for the database. I can see the DB/Table on SQL Server Object Explorer inside my Visual Studio.

My question is, how do I connect/view my SQL Server Object Explorer in Visual Studio in MSSQL Server Management Studio?

Thanks in advance! Cheers \m/

Viewing all 9386 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>