ASP.net C# Note
get Info Video => Duration etc
https://stackoverflow.com/questions/37134805/how-to-access-video-file-info-in-c-sharp
================
Duration Video Display
setInterval(test, 20000);
test is name of function
====================
get video information part 1
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_video_width2
==============
js get video duration video element
temp1.videoWidth
temp1.videoHeight
https://pretagteam.com/question/javascript-convert-seconds-to-minutes-seconds
function convertHMS(value) {
const sec = parseInt(value, 10); // convert value to number if it's string
let hours = Math.floor(sec / 3600); // get hours
let minutes = Math.floor((sec - (hours * 3600)) / 60); // get minutes
let seconds = sec - (hours * 3600) - (minutes * 60); // get seconds
// add 0 if value < 10; Example: 2 => 02
if (hours < 10) {
hours = "0" + hours;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
return hours + ':' + minutes + ':' + seconds; // Return is HH : MM : SS
}
====================
show Data from database
public static ContentUserDTO userDetail(int userID)
{
using (var dc = new ShowtimeEntities())
{
var user = (from ud in dc.UserDetails where ud.UserId == userID select ud).FirstOrDefault();
var content = (from ct in dc.Contents where ct.UserId == userID select ct).ToList();
var contentIds = content.Select(a => a.Id).ToList();
var items = dc.ContentItems.Where(a => contentIds.Contains(a.ContentId)).ToList();
var eventParticipant = (from ct in dc.EventParticipants where ct.UserId == userID select ct).ToList();
var events = (from ct in dc.Events select ct).ToList();
var contentItems = new List<ContentItemDTO>();
for (var i = 0; i < content.Count(); i++)
{
var ep = eventParticipant.Where(a => a.ContentId == content[i].Id).FirstOrDefault();
var contentType = "";
if (ep != null) contentType = events.Where(a => a.Id == ep.EventId).Select(a => a.Description).FirstOrDefault();
var qty = items.Where(a => a.ContentId == content[i].Id).Count();
var data1 = new ContentItemDTO()
{
ContentType = contentType,
ContentTitle = content[i].Title,
Quantity = qty,
CreateDate = content[i].CreateDate,
Status = content[i].Status
};
contentItems.Add(data1);
}
var data2 = new ContentUserDTO()
{
RealName = user.RealName,
DisplayName = user.DisplayName,
CotentItems = contentItems
};
return data2;
}
}
=========
key for google search : c# get image width and height from url;
for web
url : https://stackoverflow.com/questions/41436113/get-size-image-from-link
string image = @"http://img.khoahoc.tv/photos/image/2015/05/14/hang_13.jpg";
byte[] imageData = new WebClient().DownloadData(image);
MemoryStream imgStream = new MemoryStream(imageData);
Image img = Image.FromStream(imgStream);
int wSize = img.Width;
int hSize = img.Height;
key for google search : c# get image width and height from file
for lokal
url : https://stackoverflow.com/questions/6455979/how-to-get-the-the-dimensions-of-an-image-file
System.Drawing.Image img = System.Drawing.Image.FromFile(@"c:\ggs\ggs Access\images\members\1.jpg");
MessageBox.Show("Width: " + img.Width + ", Height: " + img.Height);
********
get Resolusi Image
document.getElementById('image-2245').naturalWidth;
document.getElementById('image-2245').naturalHeight;
****
Split and get data from simbol ?
get format vidio like mp4
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
let text = "videos/6egeph9fdlpn5mh1yu2f3wof3yernmww.mp4?verify=1640773482-aUK8nwuQnofDBlNpZxziYTfp1ctvvxfQ1zkziV59tlI%3d";
const myArray = text.split("?",1).toString();// this 1 is index from array text and convert to string
document.getElementById("demo").innerHTML = myArray.slice(-4);
</script>
</body>
</html>
***
This is for key or enter pres function
var input = document.getElementById("txtAgeRating");
input.addEventListener("keyup", function (event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("txtAgeRatingBtn").click();
}
});
******
get url page for page condition
@ViewContext.RouteData.Values["controller"] or you can use this code
@ViewContext.RouteData.Values["action"] and @ViewContext.RouteData.Values["controller"]
here it's for web
https://stackoverflow.com/questions/6852979/get-current-controller-in-view
key for search
asp net detect controller from view
if you want put this code to jquery you must be string this code
function changeActive() {
var a = '@ViewContext.RouteData.Values["action"]';
alert(a);
}
if you want add controller in index type this code
var changed = '@ViewContext.RouteData.Values["action"]@ViewContext.RouteData.Values["controller"]';
*******
add tags input
add code in view
<input type="text" id="txtTags" data-role="tagsinput test" placeholder="Tags">
$("#txtTags").tagsinput('add', data.Tags[0]);
add some css and js look in here
https://codepen.io/luigimj/pen/JMvRBK
here for css
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput.css
here for js
https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js
https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.min.js
https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js
***
pass data array from controller to View
using view["data"]
add code in controller
public ActionResult Transaction()
{
var Data = Repo.Repositories.getAllTransactionHeader();
ViewData["listContent"] = Data;
return View();
}
add code in repositories
public static List<TransactionHeader> getAllTransactionHeader() {
using (var dc = new AplikasiSederhanaEntities()) {
var data = from objData in dc.TransactionHeaders
orderby objData.Id descending
select objData;
return data.ToList();
}
}
add code in view
@{List<TransactionHeader> list = ViewData["listContent"] as List<TransactionHeader>;}
add code in the middle view
@foreach (var item in list) {
@item.Quantity;
}
***
using other Layout
add code in index file
Layout = "~/Views/Shared/_Default_Layout.cshtml";
then add this code in Layout file
@RenderBody()
***
Pass single Data From Controller To View
in controller type bellow
public ActionResult Index()
{
ViewBag.FirstName = "Sance";
ViewBag.LastName = "Youtube Channel";
ViewBag.Address = "Pranciss";
return View();
}
and in view type bellow
<p>First Name : @ViewBag.FirstName</p>
<p>Last Name : @ViewBag.LastName</p>
<p>Address : @ViewBag.Address</p>
****
pass list Data From Controller to view
in controller type bellow after index function
public ActionResult GetEmployee()
{
Employee employee = new Employee()
{
EmployeeID = 1,
EmployeeName = "Sance",
Address = "Babakan Wanajaya",
DateOfJoining = System.DateTime.Now,
MartialStatus = 1,
IsEligibleForLoad = true,
Salary = 15000.00m,
CreatedBy = "Admin",
CreatedDate = System.DateTime.Now
};
ViewBag.Employee = employee;
return View();
}
note : you will get error in employee code,bacause you not linked by new employee model.
you have to create a new employe model and in controller you have add link by
using PassDataFromControllerToView.Models;
in model type bellow in the middle class
public class Employee
{
//prop double tab for automatically query
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public string Address { get; set; }
public DateTime DateOfJoining { get; set; }
public int MartialStatus { get; set; }
public bool IsEligibleForLoad { get; set; }
public decimal Salary { get; set; }
public string CreatedBy { get; set; }
public DateTime CreatedDate { get; set; }
}
in view type bellow at new Employee file
<h2>Employee Details</h2>
<table class="table table-bordered table-hover">
<tr class="btn-primary">
<th>Employee ID</th>
<th>Employee Name</th>
<th>Address</th>
<th>Date Of Joining</th>
<th>Martial Status</th>
<th>Is Eligible For Loan</th>
<th>Salary</th>
<th>Created By</th>
<th>Created Date</th>
</tr>
<tr>
<td>@ViewBag.Employee.EmployeeID</td>
<td>@ViewBag.Employee.EmployeeName</td>
<td>@ViewBag.Employee.Address</td>
<td>@ViewBag.Employee.DateOfJoining</td>
<td>@if (ViewBag.Employee.MartialStatus == 1)
{
<p>Married</p>
} else {
<p>Single</p>
}
</td>
<td>@ViewBag.Employee.IsEligibleForLoad</td>
<td>@ViewBag.Employee.Salary</td>
<td>@ViewBag.Employee.CreatedBy</td>
<td>@ViewBag.Employee.CreatedDate</td>
</table>
****
0:52:52
No comments