if (ModelState.IsValid)
{
ip.patientname = fc["patientname"];
ip.patientmail = fc["patientmail"];
ip.patientcountry = fc["patientcountry"];
ip.patientquery = fc["patientquery"];
ip.SecurityCode = fc["SecurityCode"];
string url = Request.Url.AbsoluteUri;
dblayer.Add_data_pharma(ip);
TempData["msg"] = "Inserted";
}
else
{
TempData["msg"] = "Not Inserted";
}
ModelState.Clear();
return Redirect(Request.UrlReferrer.PathAndQuery);
}
string url = Request.Url.AbsoluteUri;
I want to know how to insert url name in the database using Request.Url.AbsoluteUri or any method.
public void Add_data_pharma(insert_askpharma_mar212019 ip)
{
SqlCommand com = new SqlCommand("insert_askpharma", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("#pharmaid", ip.pharmaid);
com.Parameters.AddWithValue("#patientname", ip.patientname);
com.Parameters.AddWithValue("#patientmail", ip.patientmail);
com.Parameters.AddWithValue("#patientcountry", ip.patientcountry);
com.Parameters.AddWithValue("#patientquery", ip.patientquery);
com.Parameters.AddWithValue("#SecurityCode", ip.SecurityCode);
com.Parameters.AddWithValue("#urlname", string.Empty);
com.Parameters.AddWithValue("#ipaddress", string.Empty);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
I want to insewrt the current page url in the database using mvc
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-6">
<h3 style="color:#669900">Personal Information</h3>
#using (Html.BeginForm("AskOurPharmacist", "Basic", FormMethod.Post, new { #id = "kycFormTab5" }))
{
<div class="form-group">
<label for="email">Name*</label>
<input type="text" class="form-control" id="patientname" name="patientname">
</div>
<div class="form-group">
<label for="pwd">Phone*</label>
<input type="text" class="form-control" id="" name="">
</div>
<div class="form-group">
<label for="email">Email*</label>
<input type="email" class="form-control" id="patientmail" name="patientmail">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="patientcountry" name="patientcountry">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="patientquery" name="patientquery">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="SecurityCode" name="SecurityCode">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="urlname" name="urlname">
</div>
<button type="submit" class="btn btn-success">Email me When in Stock</button>
}
</div>
<div class="col-sm-6">
<div class="rbox">
<h4 class=" text-center"><strong>Why shop with Us?</strong></h4>
<ul class="list-unstyled">
<li><i class="fa fa-heart"> </i>Trusted for Quality and Price</li>
<li><i class="fa fa-heart"> </i>80-90% Savings - Lowest Prices</li>
<li><i class="fa fa-heart"> </i>Free Shipping WorldWide*</li>
<li><i class="fa fa-heart"> </i>360° Round View of Products</li>
<li><i class="fa fa-heart"> </i>No Hidden Cost</li>
<li><i class="fa fa-heart"> </i>Saving Rewards, Referral Discounts</li>
<li><i class="fa fa-heart"> </i>Quality-Assured Medications</li>
<li class="text-right">*T&C Apply</li>
</ul>
</div>
</div>
</div>
</div>
This is my view ,in one mehod i have inserted two forms in this form only i want to insert the url in the database all are in the same table
this is my database
you must have a column(if not add 1 with name url) in database let say url which also will be available(if not add a property with the name url) in Model class ip. You method dblayer.Add_data_pharma(ip) will do the rest.
ip.url = Request.Url.AbsoluteUri;
Related
<form class="form-inline" name="form" novalidate>
<div class="sub-form" ng-form is-active ng-init="active = true" name="info">
<div class="col-md-4 col-sm-6 col-ie-4">
<div class="select-input">
<label for="xyz">Xyz *</label>
<i class="fa fa-check-circle success" ng-show="form.info.xyz.$valid"></i>
<i class="fa fa-spinner fa-spin"></i>
<i class="fa fa-times-circle error" ng-show="(form.info.xyz.$invalid && !form.info.xyz.$pristine)"></i>
<div class="styled-select">
<select
heights
name="xyz"
id="xyz"
ng-options="xyz.in as xyz.ft for xyz in xyzs"
ng-model="player.xyz"
required>
<option value="" selected="selected">-- Select --</option>
</select>
</div>
</div>
</div>
</div>
</form>
<div class="back-next-button-row">
<div class="red-button tiny-button next-button" ng-if="form.$valid">
<button ng-click="next()"><span class="button-text">Next</span><i class="fa fa-chevron-right"></i></button>
</div>
<div class="red-button tiny-button next-button" ng-if="form.$invalid">
<button ng-click="error()"><span class="button-text">Error</span><i class="fa fa-chevron-right"></i></button>
</div>
</div><!--back-next-button-row-->
In Script
$scope.form = {};
$scope.form.info = {};
$scope.formError = function () {
console.log($scope.form.info.xyz);
//Getting Object {}
}
While in html its showing proper objects that i expect
Basically I would like to check
if($scope.form.info.xyz.$invalid){
alert("Invlid")
}
I would be thankful if I came to know why this is creating problem in this prospect
With angular, you can do this inside the HTML and dont have to carry it to the script. If you want to check any form element is invalid or incomplete, you can add an element like this.
<p class="text-danger" ng-show="form.$invalid">Invalid</p>
If you still want to do on click, try the below.
In the HTML capture the form name on your function.
<button ng-click="next('form')">Validate</button>
In JS, you can have a function like the below,
$scope.next = function(form){
if ($scope[form].$valid) {
alert("True");
} else {
alert("Invalid");
}
};
I'm trying to create an upload function using angularjs. I have watch and read few tutorials in the internet. Unfortunately all the tutorials are too complicated for me because I'm still new in this field.
<form ng-submit="upload(currentUser())">
<div class="row">
<div class="form-group">
<div class="col-xs-2">
<label>Car</label>
</div>
<div class="col-xs-5">
<input type="text" placeholder="Perodua Myvi" class="form-control" ng-model="newCar" required>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-2">
<label>Price(RM) per day</label>
</div>
<div class="col-xs-5">
<input type="text" placeholder="80" class="form-control" ng-model="newPrice" required>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-2">
<label>Business Area</label>
</div>
<div class="col-xs-5">
<input type="text" placeholder="Universiti Malaysia Sabah" class="form-control" ng-model="businessArea" required>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-2">
<label>Insert Car Image</label>
<br>
</div>
<div class="col-xs-5">
<!--<button type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-picture"></span> Image
</button>-->
<input type="file"/>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-2">
</div>
<div class="col-xs-5">
<button type="submit" class="btn btn-primary btn-sm pull-right">
<span class="glyphicon glyphicon-globe"></span> Publish
</button>
</div>
<div class="col-xs-5"></div>
</div>
</div>
<br>
<br>
</form>
app.controller('postadCtrl', [
'$scope',
'auth',
function($scope, auth) {
$scope.currentUser = auth.currentUser;
$scope.posts = [];
$scope.upload = function(user) {
$scope.posts.push({
company_name: user,
car_type: $scope.newCar,
seaters: 5,
price: $scope.newPrice,
contact: 038880000,
location: $scope.businessArea
});
};
}
]);
So how do I do this in the simplest form and explanation? And how does my router and module will look like?
The output should look like this.
Am using the new implementation of uploading files which is the IFormFile. I created a view model and mapped it on a model, however, I am getting a null value on the ImageFile property of the view model. In inserting the record, I am using AngularJS to prevent it from reloading. Below is my views and controller.
public string CreateNewProduct([FromBody] ProductViewModel _product)
{
var imgFile = _product.ImageFile;
var fileName = ContentDispositionHeaderValue.Parse(imgFile.ContentDisposition).FileName.Trim('"');
var targetDirectory = Path.Combine(environment.WebRootPath, string.Format("Common\\Images\\"));
var savePath = Path.Combine(targetDirectory, fileName);
imgFile.CopyTo(new FileStream(savePath, FileMode.Create));
Products product = new Products
{
ItemCode = _product.ItemCode,
FileName = fileName,
FilePath = savePath
};
context.Products.Add(product);
context.SaveChanges();
return "";
}
And here is my view in a dialog box.
<div class="modal" role="dialog" id="addItemDialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="text-info">Add New Item</h3>
</div>
<div class="modal-body">
<form id="newproductform" class="form-horizontal" role="form" enctype="multipart/form-data">
<div class="form-group">
<span class="col-sm-3 control-label">Item Code</span>
<div class="col-sm-6">
<input type="text" class="form-control input-sm" ng-model="ItemCode" />
</div>
</div>
<div class="form-group">
<span class="col-sm-3 control-label">Image</span>
<input type="file" name="file" accept="image/*" onchange="angular.element(this).scope().selectFileforUpload(this.files)" required />
<span class="error" ng-show="(f1.file.$dirty || IsFormSubmitted) && f1.file.$error.required">Image required!</span>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success" ng-click="InsertProduct()">Submit</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
I just used the submit button but still I get null value on ImageFile property on the view model.
Here is my view model.
public class ProductViewModel
{
public string ItemCode { get; set; }
//[FileExtensions(Extensions = "jpg/jpeg")]
public IFormFile ImageFile { get; set; }
}
I am using angular directive for date picker from UI bootstrap. I also use ng-repeat to add multiple rows. I have added date picker code in ng-repeat. I have displayed these date pickers in bootstrap modal. Also ng-repeat is work fine. But if I add multiple row and click on single calendar icon then all calendar popups of all date picker are shown. I don't know why should this happened. I use is-open="$parent.opened1" to perform click on calendar button. If I use only is-open="opened1" then calendar popoup will open only once (means: can not open after selecting any date). And if I use is-open="$parent.opened1" then after adding multiple rows all calendar popup is open.
Here is my code-
<div class="modal fade bs-example-modal-lg preventiveCarePop" id="preventiveProcess" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<form role="myForm" name="myForm">
<div class="modal-dialog" style="width: 35%;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 style="margin: 0px;">
Preventive Care: <span ng-bind="patientObj.firstName"></span>
<span ng-bind="patientObj.lastName"></span><small
class="newSmall"><span> ({{patientObj.gender}}, <i
class="fa fa-mobile fa-lg"></i>:
{{patientObj.contact.mobileNumber}})
</span></small>
</h4>
</div>
<input type="hidden" ng-model="currentReminder" />
<div class="modal-body">
<div id="divActivites" name="divActivites">
<div class="form-group">
<div class="box-placeholder" ng-repeat="preventive in preventive.preventiveDetailsList">
<div class="form-group">
<div class="row">
<div class="col-lg-4">
<label for="exampleInputEmail1">Start Date<span
style="color: red;">*</span></label>
<p class="input-group">
<input type="text" class="form-control"
datepicker-popup="dd-MM-yyyy"
ng-model="preventive.startOnDate"
is-open="$parent.opened2"
id="dos-{{$index}}"
datepicker-options="dateOptions" close-text="Close"
placeholder="Select Date" required />
<span class="input-group-btn">
<button type="button" class="btn popUpCal"
ng-click="open($event,'opened2')">
<i class="fa fa-calendar"></i>
</button>
</span>
</p>
</div>
<div class="col-lg-4">
<label for="exampleInputEmail1">End Date<span
style="color: red;">*</span></label>
<p class="input-group">
<input type="text" class="form-control"
datepicker-popup="dd-MM-yyyy"
ng-model="preventive.endOnDate"
id="doe-{{$index}}"
is-open="$parent.opened1"
datepicker-options="dateOptions" close-text="Close"
placeholder="Select Date" required />
<span class="input-group-btn">
<button type="button" class="btn popUpCal"
ng-click="open($event,'opened1')" >
<i class="fa fa-calendar"></i>
</button>
</span>
</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-default" ng-click="addDummyPreventive(preventive.preventiveDetailsList,currCaseSheetObjForAddPrv.speciality,preventive.preventiveDetailsList.length)" style="float: right" title="Add new preventive"><i class="fa fa-plus-circle fa-lg"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
Here is my controller
$scope.open = function($event,opened) {
$event.preventDefault();
$event.stopPropagation();
$scope[opened] = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
I don't know what I use to work all fine.
Please share your idea's.
Thanks in advance.
Please see this demo and comments inside code can be helpful.
Html:
<div class="row" ng-repeat="dt in dates">
<div class="col-md-6">
<p class="input-group">
<input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt.date" is-open="dt.opened" datepicker-options="dateOptions" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event,dt)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
JS:
$scope.open = function($event, dt) {
$event.preventDefault();
$event.stopPropagation();
dt.opened = true;
};
MY issue is this:
When I request the data from the server this sent the data correctly but in LoginController after doing the validation I'm trying to populate the user's username and email but those variables are not being printed in the template. However if I just send those variables in a simple JSON such as $scope.details = [{ 'username':'Karman', 'username':'karman#mail.com'}]; it's working fine, what am I doing wrong? Is there some issue with ng-repeat directive?
Thanks in advance to whom can help me out with this issue.....
ps: I'm using sillex and ng-resource just in case
<body ng-controller="LoginController">
<div class="col-xs-3 details-user">
<div class="col-xs-1">
<img src="web/img/avatar.jpg" alt="..." class="img-circle">
</div>
<div class="col-xs-2">
<ul>
<li ng-repeat="detail in details">
{{detail.username}} -- {{detail.email}}
</li>
</ul>
</div>
</div>
Controller:
function LoginController($scope, Login) {
var currentResource;
$scope.login = function () {
Login.query({email: $scope.email}, function success(data){
$scope.details = data;
//$scope.details = [{ 'username':'Karman', 'username':'karman#mail.com'}];
});
}
}
Form:
<!-- Main DIV -->
<div id="login" class="login-main">
<div class="form-wrap">
<div class="form-header">
<i class="fa fa-user"></i>
</div>
<div class="form-main">
<form>
<div class="form-group">
<input ng-model="email" type="text" class="input-large" placeholder="Tu email aqui..." required>
<input ng-model="password" type="password" class="input-large" placeholder="Tu password aqui..." required>
</div>
<button ng-click="login()" ng-show='addMode' class="btn btn-success">Sign In</button>
</form><!-- end form -->
</div><!-- end div form-main -->
<div class="form-footer">
<div class="row">
<div class="col-xs-7">
<i class="fa fa-unlock-alt"></i>
Forgot password?
</div>
<div class="col-xs-5">
<i class="fa fa-check"></i>
Sign Up
</div>
</div>
</div>
</div>
</div>