public ActionResult Create([Bind(Include = "Id,Name,Description,Price,UrlImage,CategoryId")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId); return(View(product)); }
public static Boolean AddAssigment(Assignment assignment, out string errorMessage) { if (checkUploaded(assignment.Student_ID, out errorMessage) == true) { return(false); } else { try { using (var context = new AssignmentContext()) { context.Assingments.Add(assignment); context.SaveChanges(); errorMessage = ""; return(true); } } catch (Exception e) { //errorMessage = e.Message; errorMessage = "Database Error"; return(false); } } }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <returns></returns> public bool RegisterUser(RegisterModel data) { try { if (assignmentContext != null) { Users user = new Users { FirstName = data.FirstName, LastName = data.LastName, EmailId = data.EmailId, GenderId = data.GenderId, Dob = data.Dob, Password = data.Password, }; assignmentContext.Users.Add(user); assignmentContext.SaveChanges(); } return(true); } catch (Exception e) { return(false); } }
public void SaleNewMobile([FromBody] Sale sale) { using (AssignmentContext assignmentContext = new AssignmentContext()) { assignmentContext.Sale.Add(sale); assignmentContext.SaveChanges(); } }
public ActionResult Checkout([FromUri] decimal totalPr, [FromUri] string name, [FromUri] string phone, [FromUri] string email, [FromUri] string emailTitle, [FromUri] string emailText, [FromUri] string address) { Order order = new Order(); order.Customer_id = curCus.id; order.total_Price = totalPr; order.Employee_id = 1; order.shipName = name; order.shipAddress = address; order.shipPhone = phone; order.shipEmail = email; order.email_title = emailTitle; order.email_text = emailText; db.Orders.Add(order); db.SaveChanges(); var ord = db.Orders.Where(x => x.Customer_id == curCus.id).ToList().OrderByDescending(i => i.id) .FirstOrDefault(); if (ord != null) { Order_Detail orderDetail = new Order_Detail(); List <Order_Detail> cart = (List <Order_Detail>)Session["cart"]; for (int i = 0; i < cart.Count; i++) { orderDetail.Order_id = ord.id; orderDetail.Image_id = cart[i].Image.id; orderDetail.Price_id = cart[i].Price_id; orderDetail.unitPrice = cart[i].unitPrice; orderDetail.quantity = cart[i].quantity; db.Order_Detail.Add(orderDetail); db.SaveChanges(); } } return(View()); }
public Mobile AddMobile(Mobile mobile) { try { using (AssignmentContext assignmentContext = new AssignmentContext()) { assignmentContext.Mobile.Add(mobile); assignmentContext.SaveChanges(); return(mobile); } } catch (Exception) { throw; } }
public Customer AddCustomer(Customer customer) { try { using (AssignmentContext assignmentContext = new AssignmentContext()) { assignmentContext.Customer.Add(customer); assignmentContext.SaveChanges(); return(customer); } } catch (Exception) { throw; } }
public Customer UpdateCustomer(int id, Customer customer) { using (AssignmentContext assignmentContext = new AssignmentContext()) { var entity = assignmentContext.Customer.Where(mob => mob.CustId == id).FirstOrDefault(); if (entity != null) { entity.CustName = customer.CustName; entity.CustMobiile = customer.CustMobiile; entity.CustEmailId = customer.CustEmailId; entity.CustAddress = customer.CustAddress; entity.UpatedDate = System.DateTime.Now; assignmentContext.SaveChanges(); } } return(customer); }
public static void Seed(this AssignmentContext dbContext) { dbContext.Assignments.AddRange( new Assignment { Id = 1, Name = "Set A", Title = "A", Description = "", Type = "Easy", Duration = 30, Tags = new[] { "c#", ".Net" } }, new Assignment { Id = 2, Name = "Set B", Title = "B", Description = "", Type = "Difficult", Duration = 30, Tags = new[] { "C#" } }, new Assignment { Id = 3, Name = "Set C", Title = "C", Description = "", Type = "Intermediary", Duration = 60, Tags = new[] { "Java", "C#" } }, new Assignment { Id = 4, Name = "Set D", Title = "D", Description = "", Type = "Easy", Duration = 60, Tags = new[] { "Python", "Java" } } ); dbContext.SaveChanges(); }
public Task <IEnumerable <string> > Post() { //throw new Exception("Custom error thrown for script error handling test!"); if (Request.Content.IsMimeMultipartContent()) { //Simulate large file upload System.Threading.Thread.Sleep(5000); string fullPath = HttpContext.Current.Server.MapPath("~/Upload/Images/"); CustomMultipartFormDataStreamProvider streamProvider = new CustomMultipartFormDataStreamProvider(fullPath); var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } var fileInfo = streamProvider.FileData.Select(i => { var info = new FileInfo(i.LocalFileName); string url = BASE_URL + info.Name; Image image = new Image(currentCus.id, url, info.Name, info.Name); listImages.Add(image); for (int x = 0; x < listImages.Count; x++) { //System.Diagnostics.Debug.WriteLine(listImages[x].url); using (AssignmentContext db = new AssignmentContext()) { db.Images.Add(listImages[x]); db.SaveChanges(); } } return(url); }); return(fileInfo); }); return(task); } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Invalid Request!")); } }
public Mobile UpdateMobile(int id, Mobile mobile) { using (AssignmentContext assignmentContext = new AssignmentContext()) { var entity = assignmentContext.Mobile.Where(mob => mob.Id == id).FirstOrDefault(); if (entity != null) { entity.Name = mobile.Name; entity.ImeiNumber = mobile.ImeiNumber; entity.CompanyName = mobile.CompanyName; entity.Description = mobile.Description; entity.ActualPrice = mobile.ActualPrice; entity.LauchDate = mobile.LauchDate; entity.UpatedDate = System.DateTime.Now; assignmentContext.SaveChanges(); } } return(mobile); }
public IActionResult TrackIt(ClsAssignment assign) { if (!ModelState.IsValid) { ViewBag.Message = "Please enter valid Values"; return(RedirectToAction("Index")); } ClsAssignment checkAssign = context.Assignments.FirstOrDefault(item => item.Priority == assign.Priority && item.CourseName.Equals(assign.CourseName) && item.DueDate == assign.DueDate && item.AssignmentTitle.Equals(assign.AssignmentTitle) && item.Notes.Equals(assign.Notes)); if (checkAssign != null) { ViewBag.Message = "This data already exists!"; return(View("Index")); } context.Assignments.Add(assign); context.SaveChanges(); ViewBag.Message = "Tracking Successful!"; return(View("Index")); }
//GradeAssignment(student_ID, assignment_ID) Post public static void GradeAssignment(int Student_ID, Assignment Assignment, out string errorMessage) { try { using (var context = new AssignmentContext()) { var editAssingment = (from assignment in context.Assingments where assignment.Asst_ID == Assignment.Asst_ID select assignment).FirstOrDefault(); editAssingment.Feedback = Assignment.Feedback; editAssingment.Grade = Assignment.Grade; editAssingment.Status_ID = 2; context.SaveChanges(); errorMessage = ""; } } catch (Exception e) { errorMessage = "Database Problem"; } }
public ActionResult VerifyAccount(string id) { bool Status = false; using (AssignmentContext db = new AssignmentContext()) { db.Configuration.ValidateOnSaveEnabled = false; var v = db.Customers.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; v.status = 1; db.SaveChanges(); Status = true; } else { ViewBag.Message = "Invalid Request"; } } ViewBag.Status = Status; return(View()); }
public ActionResult Register([Bind(Exclude = "IsEmailVerified,ActivationCode")] PhotoUpload.Customer cus) { bool Status = false; string message = ""; if (ModelState.IsValid) { #region //Email is already Exist var isExistEmail = IsEmailExist(cus.email); var isExistUsername = IsUsernameExist(cus.username); if (isExistEmail) { ModelState.AddModelError(cus.email, "Email already exist"); return(View(cus)); } else if (isExistUsername) { ModelState.AddModelError(cus.username, "Username already exist"); return(View(cus)); } #endregion #region Generate Activation Code cus.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing cus.salt = GenerateSalt.saltStr(10); cus.password = HashPassword.CreateMD5(cus.password, cus.salt); #endregion cus.IsEmailVerified = false; #region Save to Database using (AssignmentContext db = new AssignmentContext()) { db.Customers.Add(cus); db.SaveChanges(); } //Send Email to User SendVerificationLinkEmail(cus.email, cus.ActivationCode.ToString()); message = "Registration successfully done. Account activation link " + " has been sent to your email id:" + cus.email; Status = true; #endregion } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(cus)); }