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

the value is not passing to the model variable from javascript function

$
0
0

The value of NetHrs is not passing into Model variable from the javascript function. My model class  has  the following variable.  The net Hrs is showing there on the html, but the value is not available in the controller model variable

public class BreakDownLogEntryModel
    {
         public decimal NetHrs;
}

Controller

public IActionResult BreakDownLogEntry(BreakDownLogEntryModel BreakDownLog)
        {
            if (HttpContext.Session.GetInt32("UserID") != null)
            {
                if (BreakDownLog.NetHrs == 0) // Here the value is not coming .  BreakDownLog.NetHrs is always zero. Please can you help
                {
                    ViewBag.Error = "Hrs  must be given";
                }
}
}

Html file

<div class="row"><div class="form-group"><label for="lblTJS" class="control-label col-sm-1">Time Job Start</label><div class="col-sm-2"><input type="text" class="form-control" id="TimeStart" asp-for="TimeJobStart" onchange="CalculateBreakDownRemainingHrs()"
                               onkeypress="return (event.charCode >= 48 && event.charCode <= 57) ||event.charCode == 46 || event.charCode == 0 "></div><label for="lblTJF" class="control-label col-sm-1">Time Job Finish</label><div class="col-sm-2"><input type="text" class="form-control" id="TimeEnd" asp-for="TimeJobFinish" onchange="CalculateBreakDownRemainingHrs()"
                               onkeypress="return (event.charCode >= 48 && event.charCode <= 57) ||event.charCode == 46 || event.charCode == 0 "></div><label for="lblTJF" class="control-label col-sm-1">Hrs</label><div class="col-sm-2"><input type="text" class="form-control" asp-for="NetHrs"  id="NetHrs"   ></div></div></div>




function CalculateBreakDownRemainingHrs() {
        var fromTime = $('#TimeStart').val().replace('.', ':');
        var toTime = $('#TimeEnd').val().replace('.', ':');
        var fromdate = new Date("05/25/2018 " + fromTime + ":00");
        var todate = new Date("05/25/2018 " + toTime + ":00");
        var msec = todate.getTime() - fromdate.getTime();
        var hh = Math.floor(msec / 1000 / 60 / 60);
        msec -= hh * 1000 * 60 * 60;
        var mm = Math.floor(msec / 1000 / 60);
        msec -= mm * 1000 * 60;
        var ss = Math.floor(msec / 1000);
        msec -= ss * 1000;
        netHrs = hh + "." + mm;$("#NetHrs").val(netHrs);

    }


Nuget packages containing install.ps1 scripts

$
0
0

Please see this thread that was closed without an answer: https://forums.asp.net/p/2027698/5842272.aspx

David Fowler commented on it way back then (4 years ago) to acknowledge the issue, with the answer "stay tuned".

Do we now have an outcome on this? What's the guidance for migrating a nuget package that contains install or init.ps1 scripts so that it can be used with the new project system?

Thanks

Best practice for executing tasks repeatedly

$
0
0

In the past, my company creates ConsoleApplications and calls them from the Task Scheduler on our web server. While this approach has worked perfectly fine for us in the past, it's just another thing for us to maintain, and be responsible for. For an upcoming project, we will need to check (probably 1x weekly) for any users who still need to perform a task in our website - if they haven't submitted yet, then we will generate a reminder email to each & every user that still needs to close out the week.

I was suggesting that we don't need to make a console application to do this. Really it is quite simple:

  1. Identify users that haven't submitted for the current week yet.
  2. For each user, execute an email reminder method
  3. Done...

So pretty much I am looking for a good design for implementing this weekly task to run on my website.

Net Core: Dependency Injection with Repository, Services, and other items when using XUnit

$
0
0

I am trying to conduct Dependency Injection in Xunit test for an App Service.

For some reason, the original application works and can call Customer App Service. However, it cannot call within Xunit. Below is Testserver working using Startup and Configuration from original application.
We are receiving error below:


> Message: The following constructor parameters did not have matching fixture data: ICustomerAppService customerAppService

A good reference is to use answer here from Joshua Duxbury maybe with Fixture class :

https://stackoverflow.com/questions/37724738/how-to-unit-test-asp-net-core-application-with-constructor-dependency-injection

or an answer from Mohsen Esmailpour:

https://stackoverflow.com/questions/50921675/dependency-injection-in-xunit-project/50922017#50922017


Ideal goal is to run the original application program startup/configuration, and use any dependency injection that was in startup.


namespace Testing.IntegrationTests
{
public class CustomerAppServiceTest
{
    public DBContext context;
    public ICustomerAppService customerAppService;

public CustomerAppServiceTest(ICustomerAppService customerAppService)
{
    this.customerAppService = customerAppService;
}

[Fact]
public async Task Get_CustomerById_Are_Equal()
{
    var options = new DbContextOptionsBuilder<TestContext>()
    .UseInMemoryDatabase(databaseName: "TestDatabase")
    .Options;
    context = new DbContext(options);

TestServer _server = new TestServer(new WebHostBuilder()
    .UseContentRoot("C:\\Test\\WebAPI")
    .UseEnvironment("Development")
    .UseConfiguration(new ConfigurationBuilder()
    .SetBasePath("C:\\Test\\WebAPI")
    .AddJsonFile("appsettings.json")
    .Build()).UseStartup<Startup>());

    context.Customer.Add(new Customer { CustomerId = 2, CustomerCode = "123", CustomerName = "ABC" });
    context.SaveChanges();

    var customerDto = await customerAppService.GetCustomerById(2);

    Assert.Equal("123", customerDto.CustomerCode);
}
}
}

I am receiving this error:

> Message: The following constructor parameters did not have matching fixture data: ICustomerAppService customerAppService

Need to use Dependency injection in testing just like real application.
Original application does this. Do not want Moq answer or answer which bypasses only by straight controller.

Note: ICustomerAppService has dependency on ICustomerRepository which is also injected in Startup class, and Automapper dependencies. This is why calling the whole startup class.

About hosting .Net core API app on ubuntu with nginx

Are authuntication with identity framework JWT required install entity framework ?

$
0
0

Are authentication with identity framework JWT required install entity framework ? 

I work on web application with asp.net core 2.2 and i ask Are authentication with identity framework JWT required install entity framework ?

meaning are authentication using identity framework must have entity framework core installed ?

what namespace for webapplicationfactory on intgeration test project ?

$
0
0

problem

what namespace for webapplicationfactory on intgeration test project ?

i work on asp.net core 2.1 project 

i added unit test project as xunits but when i try to define web application factory 

i dont found  any dependency for it

what tools or dll required for define webapplicationfactory on integeration test project ?

bootstrap and material issues

$
0
0

Hi,

I am using two themses in my  blazor project.

One: bootstrap 

second: MatBlazor

What issue can occurred in it if I use both ?


.NET core and amazon SNS

$
0
0

According to Amazon SNS documentation Using Amazon SNS for System-to-System Messaging with an HTTP/S Endpoint as a Subscriber I have .NET core project and want to add this feature so I subscribe with api call and created a controller and action for that, my question is how to add route user:password@domain.com and how to integrate with security as I have an Authentication security layer the idea I want to make my .net core application the callback subscriber for this 

How to create a Gantt Chart interface for ASP.NET?

$
0
0
<div style="direction: ltr; border-width: 100%;"> <div style="direction: ltr; margin-top: 0in; margin-left: 0in; width: 10.052in;"> <div style="direction: ltr; margin-top: 0in; margin-left: 0in; width: 10.052in;">

I need to develop Gantt Chart web applications for ASP.NET.

The Gantt Chart must have the following characteristics, in whole or in part, - see the Characteristics "Gantt Chart" section.

 

Mandatory requirement:

- The Gantt Chart should be able to shift dependencies between tasks.

In other words, if the tasks "Task_1" and "Task_2" have dependencies "From Finish to Start", then when the "Finish" of the task "Task_1" changes, the "Start" of the task "Task_2" changes.

 

I superficially got acquainted with demo versions:

- Syncfusion;

- telerik;

- dhtmlx;

- dlhsoft;

- Github (various options);

 

But I did not find what suits me completely. I don’t know ... Maybe I didn’t notice something ...

 

If I understand correctly, then the Gantt chart consists of the following elements separated by a splitter:

- Element-1. "Task table";

- Element-2. Gantt Chart.

 

How to implement the logic of shifting dependencies between tasks I figured out.

 

Questions.

1. What is the most effective technology for solving this problem - the "Gantt Chart" for the web?

2. Do I understand correctly that the structure of the Gantt Chart element consists of Element-1 + Element-2?

3. How to create "Element-2" ("Gantt Chart")?

 

Gantt Chart Features.

1. "Gantt chart" should have the following functionality:

1.1 "Gantt Chart":

1.1.1 Can handle the keyboard shortcut pressed by the user on the keyboard .-------------------------------------- --------------- (+ OR -) Comment

1.2 Task table:

1.2.1 Can handle the combination of keys pressed by the user on the keyboard .-------------------------------------- ---------------- (+ OR -) Comment

 

For the user"

1.3 "User" may:

1.3.1 On the "Gantt Chart":

1.3.1.1 Change the shape of the task element ("bar" that shows the duration of the task); -------------------------------- ------ (+ OR -) Comment

1.3.1.2 Change the color of the task element (“bar” that shows the duration of the task); -------------------------------- --------- (+ OR -) Comment

1.3.1.3 Replace the entire element of the task (“bar” that shows the duration of the task) with a picture (icon); ---- (+ OR -) Comment

 

1.4 "User" may:

1.4.1 In the table "Task table":

1.4.1.1 Sort the task list; ------------------------------------------- -------------------------------------------------- --------------------------------- (+ OR -) Comment

1.4.1.2 Group task list; ------------------------------------------- -------------------------------------------------- -------------------------------- (+ OR -) Comment

1.4.1.3 Filter the task list; ------------------------------------------- -------------------------------------------------- --------------------------------- (+ OR -) Comment

1.4.1.3 Add a field; -------------------------------------------- -------------------------------------------------- ------------------------------------------------ (+ OR -) Comment

1.4.1.4 Configure the formatting of the table field depending on the content of the field; ------------------------------------- ----------------- (+ OR -) Comment

 

For the "Developer"

1.5 "Developer" may:

1.5.1 On the "Gantt Chart":

1.5.1.1 Change the shape of the task element (“bar” that shows the duration of the task); -------------------------------- ----- (+ OR -). Comment

1.5.1.2 Change the color of the task element ("bar" that shows the duration of the task); -------------------------------- -------- (+ OR -). Comment

1.5.1.3 Replace the complete element of the task ("bar" that shows the duration of the task) with a picture (icon); --- (+ OR -). Comment

 

1.6 "Developer" may:

1.6.1 In the table "Task table":

1.6.1.1 Sort the task list; ------------------------------------------- -------------------------------------------------- -------------------------------- (+ OR -). Comment

1.6.1.2 Group task list; ------------------------------------------- -------------------------------------------------- ------------------------------- (+ OR -). Comment

1.6.1.3 Filter the list of tasks; ------------------------------------------- -------------------------------------------------- -------------------------------- (+ OR -). Comment

1.6.1.3 Add field; -------------------------------------------- -------------------------------------------------- ----------------------------------------------- (+ OR -). Comment

1.6.1.4 Configure the formatting of the table field depending on the content of the field; ------------------------------------- ---------------- (+ OR -). Comment

</div> </div> </div>

a quick generics question

$
0
0

I am working with a library that has an interface which implements ISomeInterface<TRequest, TResonse>

now in my class I want to use a where to state which class TResponse is, however that class is a also generic

CommonResults<T>

so something like this won't work

where TResponse : CommonResults<TResponse>, new()

because TResponse will be CommonResults<CommonResults<T>>

I want to be able to create a new instance of TResponse and add values to a property if the business logic needs to

var results = new TResponse();

but I am a little bit stuck

I could just have CommonResults but then I loose all the benefits of generics in my CommonResults<T> class

Any information would be appriciated

0x80070001 Incorrect function error While trying to install Core Hosting bundle on Windows Server 2008 R2

Format RTF from database in view

$
0
0

hi guys

how do I format or html encode Rich Text Format in my database when presenting it to a user. e.g.

Here is a sample code (As I am trying to get the <i>Jumps</i> values in italics

// in my view I am displaying database values which have been formatted in RTF formats
 @Html.DisplayFor(model => model.B)



/// my controller
   public async Task<IActionResult> Index(string Cat)
        {


            Cat = Cat.Replace("_", " ");

            ViewData["Cat"] = Cat;
            try
                {


                var x = await _context.B_Database
               .FirstOrDefaultAsync(m => m.Name == Cat);
                if (x == null)
                {
                    return NotFound();
                }

                return View(x);



/// my view results

The quick brown fox <i>Jumps</i> over the lazy dog

//

which is best for make authentication securiity identity framework or using ado.net ?

$
0
0

Problem

which is best for make authentication security using ado.net  or using identity user JWT Security ?

I work on big team working on doing ERP web system using asp.net core 2.1 .

we using Ado.net classes and function and we dont use Entity framework Core 2

we need to to make security to our system but we dont know doing it by

ado.net or identity framework ?

my function needs to done

login

register

forget password

logout

send email 

send sms

I not aware  of identity framework  security so that are using identity framework for security is good practice or using ado.net ?

I ask this question because i dont need after i start on jwt identity framework security discover some feature not exist or some thing stopped me

so that in my case i will remove it and using another option ado.net .

so that what i do 

Upload file in asp.net core web api

$
0
0

Hi I'am using asp.net core 2.2 web api, just want to ask if its possible to post file together with other model property. Please refer on this structured.

public class Attachment
{
public string PortLogNo { get; set; }
public string Description { get; set; }
public string Item { get; set; }
public DateTime? UploadedDate { get; set; }
public string FileName { get; set; }
public bool? Attached { get; set; }
public IFormFile File { get; set; }
}

My controller

<div>        [HttpPost]</div> <div>        public IActionResult AttachedFile( PortLogAttachmentVM portLogAttachmentVM)</div> <div>        {</div> <div> </div> <div>            //code here</div><div> </div> <div>            return Ok();</div> <div>        }</div> <div>I read about the IFormFile but is their another way to do it without using FromForm or just a jsonobject to post</div> <div></div><div>Thanks</div>


Angular , asp.net core web api, azure active directory

$
0
0

Hi !!!

Please help me on how to got in this. Before I use azure ad as may authentication and it is easy to set up in the later asp.net mvc. But today is different story cause my team are using angular as FE and me the .net core web api following the MVVM pattern. The problem is how can i authenticate using azure ad i mean i have no idea to do that when integrate in angular. I tried to register my web api in azure ad, assigned user then when i test my api in postman i always got the error. Please have me a tutorial and other stuff to help to do this.

something wonder in my mind

the angular send me username and password then i pass it to azure ad then what happen ? should i throw token.

Please guide me i the step by step manner

Thanks and god bless

Include Fles from Asp Net Core

$
0
0

Helo.

Is it possible to read include files from ASP Net Core?

Thanks

Make Sql Backup pragmatically in Asp.Net Core Razor Pages

$
0
0

I've been developing an Asp.Net Core Razor Pages for a school,and it's working well.I'd like to add a feature to the app so that authorized users can take backups of the database from time to time,and so they wouldn't need to log into the server to do so.I'd like the c# code I write to create the backup and then let the user choose where they would like to save the .bak file.I wonder if you could help me.The following code I've written doesn't work as it needs access to the server disk,which is not possible.

 public async Task<string> BackupDatabase()
        {
            var sqlConStrBuilder = new SqlConnectionStringBuilder(_connectionString);
            var backupFileName = $@"{_folderPath}\{sqlConStrBuilder.InitialCatalog}({DateTime.Now.Date.ToString("yyyy-MM-dd")}).bak";
            if (!System.IO.Directory.Exists(_folderPath))
            {
                System.IO.Directory.CreateDirectory(_folderPath);
            }
            using (var connection = new SqlConnection(sqlConStrBuilder.ConnectionString))
            {
                var query = $"BACKUP DATABASE [{sqlConStrBuilder.InitialCatalog}] TO DISK='{backupFileName}'";
                using (var command = new SqlCommand(query, connection))
                {
                    try
                    {
                        await connection.OpenAsync();
                        await command.ExecuteNonQueryAsync();
                        return "Backup done";
                    }
                    catch (Exception ex)
                    {
                        return "Backup encountered a problem" + "\n" + ex.Message;
                    }
                }
            }

Add WaterMark To Video

$
0
0

i want add watermark to my videos when uploaded , for example : this is test video
how to do it, 

i don't  find any tutorial for add watermark to video files in asp.net core 

How can I redirect router to 404 page?

$
0
0

I use the asp.net core MVC and redirect the page to an HTML suffix like this:

[Route("al.html")]
public IActionResult allen()
{
return View();
}

When I input the URL http://localhost:5009/al.html and it works.

Now if I access the URL which is inexistent such as http://localhost:5009/all.html

The browser only shows the following text:

{"code":"40310014","msg":"invalid Referer header"}

Well, now I want it not to show the text above but redirect to the 404page.

How can I achieve this? Thank you.

Viewing all 9386 articles
Browse latest View live


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