public ActionResult SignUp(FormCollection formdata) { Dbcontext db = new Dbcontext(); User u = new User(); if (ModelState.IsValid) { try { u.Fullname = Convert.ToString(formdata["Fullname"]); u.Email = Convert.ToString(formdata["Email"]); u.Loginid = Convert.ToString(formdata["Loginid"]); u.DateofBirth = Convert.ToDateTime(formdata["DateofBirth"]); u.Password = Convert.ToString(formdata["Password"]); u.ConfirmPassword = Convert.ToString(formdata["ConfirmPassword"]); u.State = Convert.ToString(formdata["State"]); u.MobileNo = Convert.ToInt64(formdata["MobileNo"]); u.City = formdata["City"]; u.Cnic = Convert.ToInt64(formdata["Cnic"]); u.Gender = new Gender { Id = Convert.ToInt32(formdata["gender.Name"]) }; u.Role = new Role() { Id = 2 }; u.Shift = formdata["Shift"]; u.FullAddress = formdata["FullAddress"]; int counter = 0; long uno = DateTime.Now.Ticks; foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; if (!string.IsNullOrEmpty(file.FileName)) { string abc = uno + "_" + ++counter + file.FileName.Substring(file.FileName.LastIndexOf(".")); string url = "~/Content/Images/" + abc; string path = Request.MapPath(url); u.ImageUrl = abc; file.SaveAs(path); } } db.Users.Add(u); db.Entry(u.Role).State = EntityState.Unchanged; db.Entry(u.Gender).State = EntityState.Unchanged; db.SaveChanges(); return(RedirectToAction("Login", "Users")); } catch (Exception) { throw; } } else { return(null); } }
public ActionResult AddMember(FormCollection formdata) { Dbcontext dbcontext = new Dbcontext(); Member member = new Member(); if (ModelState.IsValid) { try { member.FullName = formdata["FullName"]; member.CNIC = Convert.ToInt64(formdata["CNIC"]); member.MobileNo = Convert.ToInt64(formdata["MobileNo"]); member.Gender = new Gender { Id = Convert.ToInt32(formdata["Gender.Name"]) }; member.Instructer = new Instructer { Id = Convert.ToInt32(formdata["instructor"]) }; member.FullAddress = formdata["FullAddress"]; member.DateofBirth = Convert.ToDateTime(formdata["DateofBirth"]); member.CurrentDate = Convert.ToDateTime(formdata["CurrentDate"]); member.Fee = Convert.ToInt32(formdata["Fee"]); member.SubmissionDate = Convert.ToDateTime(formdata["SubmissionDate"]); member.SubmitTo = formdata["SubmitTo"]; member.RollNo = Convert.ToInt32(formdata["RollNo"]); int counter = 0; long uno = DateTime.Now.Ticks; foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; if (!string.IsNullOrEmpty(file.FileName)) { string abc = uno + "_" + ++counter + file.FileName.Substring(file.FileName.LastIndexOf(".")); string url = "~/Content/MemberPics/" + abc; string path = Request.MapPath(url); member.ImageUrl = abc; file.SaveAs(path); } } dbcontext.Members.Add(member); dbcontext.Entry(member.Gender).State = EntityState.Unchanged; dbcontext.Entry(member.Instructer).State = EntityState.Unchanged; dbcontext.SaveChanges(); return(RedirectToAction("Message")); } catch (Exception e) { Console.WriteLine(e); throw; } } return(View()); }
public ActionResult EditCourse(Course model) { if (ModelState.IsValid) { using (_db) { var courseToChange = _db.courses.Find(model.Id); if (!model.Title.IsNullOrWhiteSpace()) { courseToChange.Title = model.Title; } if (!model.Description.IsNullOrWhiteSpace()) { courseToChange.Description = model.Description; } if (!model.Teacher.IsNullOrWhiteSpace()) { courseToChange.Teacher = model.Teacher; } _db.Entry(courseToChange).State = System.Data.Entity.EntityState.Modified; _db.SaveChanges(); } return(RedirectToAction("CourseIndex")); } else { ModelState.AddModelError("", "Incorrect format has been placed"); } return(RedirectToAction("CourseIndex")); }
public ActionResult EditAssignment(Assignment model) { if (ModelState.IsValid) { using (_db) { var assignmentToChange = _db.assignments.Find(model.Id); if (!model.Title.IsNullOrWhiteSpace()) { assignmentToChange.Title = model.Title; } if (!model.Description.IsNullOrWhiteSpace()) { assignmentToChange.Description = model.Description; } if (model.TimeEnds.HasValue) { assignmentToChange.TimeEnds = model.TimeEnds; } _db.Entry(assignmentToChange).State = System.Data.Entity.EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("/Course/" + assignmentToChange.CourseId)); } } else { ModelState.AddModelError("", "Incorrect format has been placed"); } return(RedirectToAction("/Course/" + model.CourseId)); }
public void EditLink(ViewEditLink viewLink) { try { Link link = db.link.FirstOrDefault(p => p.id == viewLink.id); link.title = viewLink.title; link.url = viewLink.url; db.Entry(link).State = EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { System.ArgumentException argEx = new System.ArgumentException(ex.Message); throw argEx; } }
public ActionResult UpdateUser(User user) { Dbcontext db = new Dbcontext(); using (db) { int counter = 0; long uno = DateTime.Now.Ticks; foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; if (!string.IsNullOrEmpty(file.FileName)) { string abc = uno + "_" + ++counter + file.FileName.Substring(file.FileName.LastIndexOf(".")); string url = "~/Content/Images/" + abc; string path = Request.MapPath(url); user.ImageUrl = abc; file.SaveAs(path); } } db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("UserDetails", "Admin")); }
/// <summary> /// 批量插入 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entities"></param> /// <returns></returns> public int Insert <T>(List <T> entities) where T : class { foreach (var entity in entities) { Dbcontext.Entry <T>(entity).State = EntityState.Added; } return(DbTransaction == null?this.Commit() : 0); }
public ActionResult Edit([Bind(Include = "ProductID,OrderID,ProductName,Quantity,Price")] OrderDetail orderDetail) { if (ModelState.IsValid) { db.Entry(orderDetail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orderDetail)); }
public ActionResult Edit([Bind(Include = "ID,Name,Code,MetaTitle,Description,Image,MoreImages,Price,PromotionPrice,IncludeVAT,Quantity,CategoryID,Detail,Warranty,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,TopHot,ViewCount")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Edit([Bind(Include = "ID,CreateDate,CustomerID,ShipName,ShipMobile,ShipAddress,ShipEmail,Status")] Order order) { if (ModelState.IsValid) { db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(order)); }
public ActionResult Edit([Bind(Include = "ID,Name,MetaTitle,ParentID,DisplayOrder,SeoTitle,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,ShowOnHome")] ProductCategory productCategory) { if (ModelState.IsValid) { db.Entry(productCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productCategory)); }
public ActionResult UpdateInstructor(Instructer instructer) { Dbcontext db = new Dbcontext(); using (db) { db.Entry(instructer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Instructor")); } }
public ActionResult DeleteAttandance(int id) { Dbcontext db = new Dbcontext(); Attandance p = (from c in db.Attandances where c.Id == id select c).FirstOrDefault(); db.Entry(p).State = EntityState.Deleted; db.SaveChanges(); return(Json("Delete", JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteMember(int id) { Dbcontext db = new Dbcontext(); Member member = (from c in db.Members .Include(x => x.Gender) where c.Id == id select c).FirstOrDefault(); db.Entry(member).State = EntityState.Deleted; db.SaveChanges(); return(Json("Delete", JsonRequestBehavior.AllowGet)); }
public ActionResult Edit([Bind(Include = "ID,UserName,PassWord,Name,Address,Email,Phone,Image,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Status")] User user) { if (ModelState.IsValid) { SetAlert("Sua thanh cong", "success"); user.PassWord = Encriptor.MD5Hash(user.PassWord); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult DeleteVideo(int id) { Dbcontext db = new Dbcontext(); using (db) { Video video = (from c in db.Videos where c.Id == id select c).FirstOrDefault(); db.Entry(video).State = EntityState.Deleted; db.SaveChanges(); } return(Json("Delete", JsonRequestBehavior.AllowGet)); }
public ActionResult SubmitPayment(FormCollection formdata) { Dbcontext db = new Dbcontext(); Payment payment = new Payment(); if (ModelState.IsValid) { payment.Name = formdata["Name"]; payment.FeeDate = Convert.ToDateTime(formdata["FeeDate"]); payment.PaidAmount = Convert.ToInt32(formdata["PaidAmount"]); payment.RollNo = Convert.ToInt32(formdata["RollNo"]); Member mem = new MemberHandler().GetUserByRollNo(payment.RollNo); payment.Member = mem; mem.TotalPaidAmount = mem.TotalPaidAmount + Convert.ToInt32(formdata["PaidAmount"]); db.Payments.Add(payment); db.Entry(payment.Member).State = EntityState.Unchanged; db.Entry(mem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("index")); } return(View()); }
public JsonResult DeleteUesr(int id) { Dbcontext db = new Dbcontext(); User p = (from c in db.Users .Include(x => x.Role) .Include(x => x.Gender) where c.Id == id select c).FirstOrDefault(); db.Entry(p).State = EntityState.Deleted; db.SaveChanges(); return(Json("Delete", JsonRequestBehavior.AllowGet)); }
public ActionResult UpdatePayment(Payment payment) { Dbcontext db = new Dbcontext(); using (db) { if (payment?.Id != null) { db.Entry(payment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } return(View()); }
public ActionResult MarkAttandance(FormCollection data) { AttandanceHandler aHandler = new AttandanceHandler(); Dbcontext db = new Dbcontext(); try { if (ModelState.IsValid) { Attandance attandance = new Attandance(); attandance.AttandanceDdl = new AttandanceDDL { Id = Convert.ToInt32(data["os"]) }; attandance.DateTime = Convert.ToDateTime(data["DateTime"]); attandance.Member = new Member { Id = Convert.ToInt32(data["Id"]) }; db.Attandances.Add(attandance); db.Entry(attandance.AttandanceDdl).State = EntityState.Unchanged; db.Entry(attandance.Member).State = EntityState.Unchanged; db.SaveChanges(); return(RedirectToAction("index")); } } catch (Exception e) { ViewBag.OSList = ModelHelper.ToSelectItemList(aHandler.GetAttandances()); Console.WriteLine(e); throw; } return(RedirectToAction("Error")); }
public ActionResult UpdateMember(Member member) { Dbcontext db = new Dbcontext(); using (db) { if (member?.Id != null) { db.Entry(member).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); } }
public string DeleteAccountBalance(int year, int month) { accountbalance accountToDelete = DbContext.accountbalances.Where(o => o.year == year && o.month == month).FirstOrDefault(); DbContext.Entry(accountToDelete).State = System.Data.Entity.EntityState.Deleted; int result = DbContext.SaveChanges(); if (result != 0) { return("deleted successfully"); } else { return("Error occured while deleting"); } }
public string DeleteUser(string username) { user userToDelete = DbContext.users.Where(o => o.username == username).FirstOrDefault(); DbContext.Entry(userToDelete).State = System.Data.Entity.EntityState.Deleted; int result = DbContext.SaveChanges(); if (result != 0) { return("deleted successfully"); } else { return("Error occured while deleting"); } }
/// <summary> ///更新 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public int Update <T>(T entity) where T : class { Dbcontext.Set <T>().Attach(entity); Hashtable props = ConvertExtension.GetPropertyInfo <T>(entity); foreach (string item in props.Keys) { if (item != "PK") { object value = Dbcontext.Entry(entity).Property(item).CurrentValue; if (value != null) { if (value.ToString() == " ") { Dbcontext.Entry(entity).Property(item).CurrentValue = null; } Dbcontext.Entry(entity).Property(item).IsModified = true; } } } return(DbTransaction == null?this.Commit() : 0); }
public void UpdateRecord(ProductSold pSold) { Dbcontext.Entry(pSold).State = EntityState.Modified; }
/// <summary> /// 实体插入 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public int Insert <T>(T entity) where T : class { Dbcontext.Entry <T>(entity).State = EntityState.Added; return(DbTransaction == null?this.Commit() : 0); }