var delete = _context.ProductColours.Find(colour.Id);
delete.DeletedAt = DateTime.Now;
_context.Entry(delete).State = EntityState.Modified;
_context.SaveChanges();
Saturday, November 21, 2015
Add
Size itemSize = new Size
{
Description = description,
IsActive = status == 1,
CreatedAt = DateTime.Now,
CreatedBy = userId,
ModifiedAt = DateTime.Now
};
_context.Sizes.Add(itemSize);
_context.SaveChanges();
{
Description = description,
IsActive = status == 1,
CreatedAt = DateTime.Now,
CreatedBy = userId,
ModifiedAt = DateTime.Now
};
_context.Sizes.Add(itemSize);
_context.SaveChanges();
Saturday, August 22, 2015
MVC Design
@using (Html.BeginForm(MVC.Cart.Cart.ActionNames.Checkout, MVC.Cart.Cart.Name, FormMethod.Post))
{
<table>
<tr>
<td>Name : @Html.TextBoxFor(c=>c.Name)</td>
</tr>
<tr>
<td>Email : @Html.TextBoxFor(c=>c.Email) </td>
</tr>
<tr>
<td><button type="submit">Add to cart</button></td>
</tr>
</table>
}
@using (Html.BeginForm(MVC.Account.ActionNames.LogOff, MVC.Account.Name, new { area = "" }, FormMethod.Post, new { id = "logoutForm" }))
{
@Html.AntiForgeryToken()
<td><button type="submit">Ok</button></td>
@*@Html.ActionLink("OK", MVC.Account.ActionNames.LogOff, MVC.Account.Name, new {area = ""}, null)*@
}
@foreach (var product in Model.Products)
{
<tr>
<td>@product.ProductName</td>
<td>@product.Price</td>
<td>@Html.ActionLink("View", MVC.Cart.Cart.ActionNames.ViewItem, MVC.Cart.Cart.Name, new { itemId = @product.Id },new {})</td>
</tr>
}
{
<table>
<tr>
<td>Name : @Html.TextBoxFor(c=>c.Name)</td>
</tr>
<tr>
<td>Email : @Html.TextBoxFor(c=>c.Email) </td>
</tr>
<tr>
<td><button type="submit">Add to cart</button></td>
</tr>
</table>
}
@using (Html.BeginForm(MVC.Account.ActionNames.LogOff, MVC.Account.Name, new { area = "" }, FormMethod.Post, new { id = "logoutForm" }))
{
@Html.AntiForgeryToken()
<td><button type="submit">Ok</button></td>
@*@Html.ActionLink("OK", MVC.Account.ActionNames.LogOff, MVC.Account.Name, new {area = ""}, null)*@
}
@foreach (var product in Model.Products)
{
<tr>
<td>@product.ProductName</td>
<td>@product.Price</td>
<td>@Html.ActionLink("View", MVC.Cart.Cart.ActionNames.ViewItem, MVC.Cart.Cart.Name, new { itemId = @product.Id },new {})</td>
</tr>
}
MVC
http://csharp.net-informations.com/xml/how-to-read-xml.htm
AutomaticMigrationsEnabled = true;
[Required(ErrorMessage = "Please Enter Email")]
public TestContext()
: base("name=TestContext")
{
}
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-ShoppingCart.UI2-20150822143412;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-ShoppingCart.UI2-20150822143412.mdf" providerName="System.Data.SqlClient" />
<add name="TestContext" providerName="System.Data.SqlClient" connectionString="Server=DELL;initial catalog=Test;User ID=sa;Password=snd;Min Pool Size=2" />
{
public class TestResponse
{
public List<TestItem> TestItems { get; set; }
public double Total { get; set; }
}
public class TestItem
{
public int Id { get; set; }
public string ProductName { get; set; }
public double Price { get; set; }
public int Qty { get; set; }
public double Total { get; set; }
}
}
public int Add(int id, double price, int qty, string userSession,int cartId)
{
var cart = _shoppingCartContext.Carts.Where(c => c.Id == cartId);
var product = _shoppingCartContext.Products.Where(c => c.Id == id);
CartDetail cartDetail = new CartDetail
{
Cart = cart.FirstOrDefault(),
Product = product.FirstOrDefault(),
Qty = qty,
Total = price*qty,
CreatedAt = DateTime.Now
};
var cartDetailResponce = _shoppingCartContext.CartDetails.Add(cartDetail);
_shoppingCartContext.SaveChanges();
return cartDetailResponce.Id;
}
public void Update(int cartId,string name,string email)
{
var cart = _shoppingCartContext.Carts.FirstOrDefault(c => c.Id == cartId);
var newCart = new Cart
{
Id = cart.Id,
UserName = cart.UserName,
UserSession = cart.UserSession,
CreatedAt = DateTime.Now,
Name = name,
Email = email,
IsCheckout = true
};
_shoppingCartContext.Entry(cart).CurrentValues.SetValues(newCart);
_shoppingCartContext.SaveChanges();
}
public void DeleteItem(int itemId)
{
var item = _shoppingCartContext.CartDetails.FirstOrDefault(c => c.Id == itemId);
_shoppingCartContext.CartDetails.Remove(item);
_shoppingCartContext.SaveChanges();
}
string userSession = Guid.NewGuid().ToString();
Session["UserSession"] = userSession;
int cartId = cartService.StartCart(userSession,model.UserName);
Session["CartId"] = cartId.ToString();
public virtual ActionResult Index()
{
CartService cartService = new CartService();
var products = cartService.GetAllProduct();
var productList = new List<ProductData>();
foreach (var product in products)
{
var productData = new ProductData
{
Id = product.Id,
Price = product.Price,
ProductName = product.ProductName
};
productList.Add(productData);
}
ProductResponse response=new ProductResponse();
response.Products = productList;
return View(response);
}
[HttpGet]
public virtual ActionResult ViewItem(int itemId)
{
CartService cartService = new CartService();
var product = cartService.GetProductById(itemId);
ProductRequest productRequest = new ProductRequest
{
Id = product.Id,
Price = product.Price,
ProductName = product.ProductName,
Qty = 1
};
return View(productRequest);
}
public virtual ActionResult AddItem(ProductRequest productRequest)
{
string userSession = Session["UserSession"].ToString();
int cartId =Convert.ToInt32(Session["CartId"].ToString());
CartService cartService = new CartService();
cartService.AddToCart(productRequest.Id, productRequest.Price, productRequest.Qty, userSession, cartId);
return RedirectToAction(MVC.Cart.Cart.ViewCart());
}
public virtual ActionResult ViewCart()
{
int cartId = Convert.ToInt32(Session["CartId"].ToString());
CartService cartService = new CartService();
var cartItems = cartService.GetAllCartItems(cartId);
var cartItemList = new List<CartItem>();
double total = 0;
foreach (var item in cartItems)
{
var cartItem = new CartItem
{
Id = item.Id,
ProductName = item.Product.ProductName,
Price = item.Product.Price,
Qty = item.Qty,
Total = item.Total
};
cartItemList.Add(cartItem);
total = total + item.Total;
}
CartResponse response=new CartResponse();
response.CartItems = cartItemList;
response.Total = total;
return View(response);
}
public virtual ActionResult Checkout()
{
var checkout = new CheckoutRequest();
return View(checkout);
}
[HttpPost]
public virtual ActionResult Checkout(CheckoutRequest checkoutRequest)
{
var checkout = new CheckoutRequest();
int cartId = Convert.ToInt32(Session["CartId"].ToString());
CartService cartService = new CartService();
cartService.Checkout(cartId, checkoutRequest.Name, checkoutRequest.Email);
return RedirectToAction(MVC.Cart.Cart.ActionNames.Complete, MVC.Cart.Cart.Name, new { cartId = cartId });
}
public virtual ActionResult Complete(int cartId)
{
CartService cartService = new CartService();
var response= cartService.Summery(cartId);
return View(response);
}
public virtual ActionResult DeleteItem(int itemId)
{
CartService cartService = new CartService();
cartService.DeleteItem(itemId);
return RedirectToAction(MVC.Cart.Cart.ViewCart());
}
---------------------------------------------------------------------------------------------------------------------
@using (Ajax.BeginForm(MVC.Student.ActionNames.EditStudent, MVC.Student.Name, FormMethod.Post, new AjaxOptions { UpdateTargetId = updatedId, InsertionMode = InsertionMode.Replace, OnSuccess = "OnAjaxCallSuccess()" }))
{}
--------------------------------------------------------------------------------------------------------------------
string returnUrl = "window.location =' " + hostName + redirectUrl+"'";
return JavaScript(returnUrl);
AutomaticMigrationsEnabled = true;
[Required(ErrorMessage = "Please Enter Email")]
public TestContext()
: base("name=TestContext")
{
}
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-ShoppingCart.UI2-20150822143412;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-ShoppingCart.UI2-20150822143412.mdf" providerName="System.Data.SqlClient" />
<add name="TestContext" providerName="System.Data.SqlClient" connectionString="Server=DELL;initial catalog=Test;User ID=sa;Password=snd;Min Pool Size=2" />
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
namespace Test.Service.Models{
public class TestResponse
{
public List<TestItem> TestItems { get; set; }
public double Total { get; set; }
}
public class TestItem
{
public int Id { get; set; }
public string ProductName { get; set; }
public double Price { get; set; }
public int Qty { get; set; }
public double Total { get; set; }
}
}
public int Add(int id, double price, int qty, string userSession,int cartId)
{
var cart = _shoppingCartContext.Carts.Where(c => c.Id == cartId);
var product = _shoppingCartContext.Products.Where(c => c.Id == id);
CartDetail cartDetail = new CartDetail
{
Cart = cart.FirstOrDefault(),
Product = product.FirstOrDefault(),
Qty = qty,
Total = price*qty,
CreatedAt = DateTime.Now
};
var cartDetailResponce = _shoppingCartContext.CartDetails.Add(cartDetail);
_shoppingCartContext.SaveChanges();
return cartDetailResponce.Id;
}
public void Update(int cartId,string name,string email)
{
var cart = _shoppingCartContext.Carts.FirstOrDefault(c => c.Id == cartId);
var newCart = new Cart
{
Id = cart.Id,
UserName = cart.UserName,
UserSession = cart.UserSession,
CreatedAt = DateTime.Now,
Name = name,
Email = email,
IsCheckout = true
};
_shoppingCartContext.Entry(cart).CurrentValues.SetValues(newCart);
_shoppingCartContext.SaveChanges();
}
public void DeleteItem(int itemId)
{
var item = _shoppingCartContext.CartDetails.FirstOrDefault(c => c.Id == itemId);
_shoppingCartContext.CartDetails.Remove(item);
_shoppingCartContext.SaveChanges();
}
string userSession = Guid.NewGuid().ToString();
Session["UserSession"] = userSession;
int cartId = cartService.StartCart(userSession,model.UserName);
Session["CartId"] = cartId.ToString();
public virtual ActionResult Index()
{
CartService cartService = new CartService();
var products = cartService.GetAllProduct();
var productList = new List<ProductData>();
foreach (var product in products)
{
var productData = new ProductData
{
Id = product.Id,
Price = product.Price,
ProductName = product.ProductName
};
productList.Add(productData);
}
ProductResponse response=new ProductResponse();
response.Products = productList;
return View(response);
}
[HttpGet]
public virtual ActionResult ViewItem(int itemId)
{
CartService cartService = new CartService();
var product = cartService.GetProductById(itemId);
ProductRequest productRequest = new ProductRequest
{
Id = product.Id,
Price = product.Price,
ProductName = product.ProductName,
Qty = 1
};
return View(productRequest);
}
public virtual ActionResult AddItem(ProductRequest productRequest)
{
string userSession = Session["UserSession"].ToString();
int cartId =Convert.ToInt32(Session["CartId"].ToString());
CartService cartService = new CartService();
cartService.AddToCart(productRequest.Id, productRequest.Price, productRequest.Qty, userSession, cartId);
return RedirectToAction(MVC.Cart.Cart.ViewCart());
}
public virtual ActionResult ViewCart()
{
int cartId = Convert.ToInt32(Session["CartId"].ToString());
CartService cartService = new CartService();
var cartItems = cartService.GetAllCartItems(cartId);
var cartItemList = new List<CartItem>();
double total = 0;
foreach (var item in cartItems)
{
var cartItem = new CartItem
{
Id = item.Id,
ProductName = item.Product.ProductName,
Price = item.Product.Price,
Qty = item.Qty,
Total = item.Total
};
cartItemList.Add(cartItem);
total = total + item.Total;
}
CartResponse response=new CartResponse();
response.CartItems = cartItemList;
response.Total = total;
return View(response);
}
public virtual ActionResult Checkout()
{
var checkout = new CheckoutRequest();
return View(checkout);
}
[HttpPost]
public virtual ActionResult Checkout(CheckoutRequest checkoutRequest)
{
var checkout = new CheckoutRequest();
int cartId = Convert.ToInt32(Session["CartId"].ToString());
CartService cartService = new CartService();
cartService.Checkout(cartId, checkoutRequest.Name, checkoutRequest.Email);
return RedirectToAction(MVC.Cart.Cart.ActionNames.Complete, MVC.Cart.Cart.Name, new { cartId = cartId });
}
public virtual ActionResult Complete(int cartId)
{
CartService cartService = new CartService();
var response= cartService.Summery(cartId);
return View(response);
}
public virtual ActionResult DeleteItem(int itemId)
{
CartService cartService = new CartService();
cartService.DeleteItem(itemId);
return RedirectToAction(MVC.Cart.Cart.ViewCart());
}
---------------------------------------------------------------------------------------------------------------------
@using (Ajax.BeginForm(MVC.Student.ActionNames.EditStudent, MVC.Student.Name, FormMethod.Post, new AjaxOptions { UpdateTargetId = updatedId, InsertionMode = InsertionMode.Replace, OnSuccess = "OnAjaxCallSuccess()" }))
{}
--------------------------------------------------------------------------------------------------------------------
string returnUrl = "window.location =' " + hostName + redirectUrl+"'";
return JavaScript(returnUrl);
Read XML C#
XmlDataDocument xmldoc = new XmlDataDocument();
XmlNodeList xmlnode;
int i = 0;
string str = null;
FileStream fs = new FileStream(Server.MapPath("~/XMLFile1.xml"), FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
xmlnode = xmldoc.GetElementsByTagName("Employee");
for (i = 0; i <= xmlnode.Count - 1; i++)
{
var name= xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
var email = xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
//str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim() + " " + xmlnode[i].ChildNodes.Item(1).InnerText.Trim() + " " + xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
//MessageBox.Show(str);
}
XmlNodeList xmlnode;
int i = 0;
string str = null;
FileStream fs = new FileStream(Server.MapPath("~/XMLFile1.xml"), FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
xmlnode = xmldoc.GetElementsByTagName("Employee");
for (i = 0; i <= xmlnode.Count - 1; i++)
{
var name= xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
var email = xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
//str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim() + " " + xmlnode[i].ChildNodes.Item(1).InnerText.Trim() + " " + xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
//MessageBox.Show(str);
}
Subscribe to:
Comments (Atom)