public void Update(GenreBL genre) { var item = AutoMapperBL <GenreBL, Genre> .Map(genre); Dbcontext.UowRepositoryGenres.Update(item); Dbcontext.Save(); }
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 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> public int Commit() { try { int returnValue = Dbcontext.SaveChanges(); if (DbTransaction != null) { DbTransaction.Commit(); this.Close(); } return(returnValue); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException is SqlException) { SqlException sqlEx = ex.InnerException.InnerException as SqlException; string msg = ExceptionMessageHelper.GetSqlExceptionMessage(sqlEx.Number); throw DataAccessException.ThrowDataAccessException(sqlEx, msg); } throw; } finally { if (DbTransaction == null) { this.Close(); } } }
public List <AttandanceDDL> GetDDL() { using (Dbcontext db = new Dbcontext()) { return((from c in db.AttandanceDdls select c).ToList()); } }
public ActionResult AddImages(Image images) { Dbcontext db = new Dbcontext(); 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/GalleryImages/" + abc; string path = Request.MapPath(url); images.ImageUrl = abc; file.SaveAs(path); } } using (db) { db.Images.Add(images); db.SaveChanges(); } return(View()); }
public bool Create(UserBL user) { if (null == user) { return(false); } if (null != Dbcontext.UowRepositoryUsers.Find(q => q.Login == user.Login)) { return(false); } var item = new User() { Login = user.Login, Email = user.Email, Password = user.Password }; Dbcontext.UowRepositoryUsers.Create(item); try { Dbcontext.Save(); } catch (System.Exception) { return(false); } return(true); }
protected override void Seed(Dbcontext context) { var users = new List <User> { new User { Email = "*****@*****.**", FirstName = "abc", LastName = "def", Password = "******", ModifiedOn = DateTime.Now, CreatedOn = DateTime.Now } }; users.ForEach(s => context.Users.AddOrUpdate(s)); context.SaveChanges(); var events = new List <BookReadingEvent> { new BookReadingEvent { ModifiedOn = DateTime.Now, CreatedOn = DateTime.Now, BookTitle = "RishavBook", Date = DateTime.Now, Location = "Best PG", StartTime = "1", Type = Shared.CustomDataTypes.EventType.Public, UserID = 1 } }; events.ForEach(s => context.BookReadingEvents.AddOrUpdate(s)); context.SaveChanges(); // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. }
public async void GetVehicleBrands() { try { var result = Dbcontext.GetCompanyVehicleBrands(Application.Current.Properties["UN"].ToString(), Application.Current.Properties["PW"].ToString(), Application.Current.Properties["Ucid"].ToString(), Convert.ToInt32(Application.Current.Properties["CompanyId"].ToString())); AllVehicleBrands = new ObservableCollection <VehicleBrand>(); VehicleBrand brand; if (result != null) { if (result.Length > 0) { foreach (var data in result) { brand = new VehicleBrand(); brand.Id = data.Id; brand.Name = data.Name; AllVehicleBrands.Add(brand); } } } GetErrorCodes(); } catch (Exception e) { IsBusy = false; await Application.Current.MainPage.DisplayAlert("Fel", e.Message, "Stäng"); } }
/// <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 UnitTest1() { context = new Dbcontext(); Arepository = new AccountRepository(context); Prepository = new ProductRepository(context); Crepository = new CategoryRepository(context); accController = new AccountController(); }
public ActionResult SearchStudent() { using (Dbcontext db = new Dbcontext()) { var data = db.Members.Include(m => m.Gender).OrderBy(x => x.FullName).ToList(); return(View(data)); } }
public void DeleteWork(int id) { if (0 >= id) { return; } Dbcontext.UowRepositoryWorks.Delete(id); Dbcontext.Save(); }
/// <summary> /// 登录验证 /// </summary> /// <param name="userName"></param> /// <param name="userPassword"></param> /// <returns></returns> public ActionResult Enter(string userName, string userPassword, string verifyCode) { using (Dbcontext context = new Dbcontext()) { // 第一步检验验证码 // 从缓存获取验证码作为校验基准 // 先用当前类的全名称拼接上字符串 “verifyCode” 作为缓存的key Cache cache = new Cache(); var verifyCodeKey = $"{this.GetType().FullName}_verifyCode"; object cacheobj = cache.Get(verifyCodeKey); if (cacheobj == null) { return(Json(new { success = false, Message = "验证码已失效" }, JsonRequestBehavior.AllowGet)); }// 不区分大小写 比较 else if (!(cacheobj.ToString().Equals(verifyCode, StringComparison.CurrentCultureIgnoreCase))) { return(Json(new { success = false, Message = "验证码错误" }, JsonRequestBehavior.AllowGet)); } cache.Remove(verifyCodeKey); User_infor userinfo = context.User_infor.FirstOrDefault(u => u.User_name == userName); if (userinfo == null) { return(Json(new { success = false, Message = "当前用户不存在", }, JsonRequestBehavior.AllowGet)); } if (MD5Encrypt.Encrypt(userPassword) != userinfo.User_pwd) { return(Json(new { success = false, Message = "密码错误", }, JsonRequestBehavior.AllowGet)); } //用session确认用户已经登录 HttpContext.Session["CurentUser"] = userinfo; HttpContext.Session.Timeout = 2; return(Json(new { success = true, Message = "登录成功", }, JsonRequestBehavior.AllowGet)); } }
public int GetUserCount() { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Users select c).Count()); } }
public List <Contact> GetAllMessages() { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Contacts select c).ToList()); } }
public List <Attandance> GetAttandancebyRollNo(int rollNo) { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Attandances.Include(m => m.Member).Include(m => m.AttandanceDdl) where c.Member.RollNo == rollNo select c).ToList()); } }
public Member GetUserByRollNo(int rollno) { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Members where c.RollNo == rollno select c).FirstOrDefault()); } }
public int GetVideosCount() { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Videos select c).Count()); } }
public int GetAttandanceCount() { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Attandances select c).Count()); } }
public int GetPaymentCount() { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Members select c).Count()); } }
public List <Gender> GetGender() { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Genders select c).ToList()); } }
public int GetInstrCount() { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Instructers select c).Count()); } }
public int GetcontactCount() { Dbcontext db = new Dbcontext(); using (db) { return((from c in db.Contacts select c).Count()); } }
/// <summary> /// 批量删除 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entities"></param> /// <returns></returns> public int Delete <T>(List <T> entities) where T : class { foreach (var entity in entities) { Dbcontext.Set <T>().Attach(entity); Dbcontext.Set <T>().Remove(entity); } return(DbTransaction == null?this.Commit() : 0); }
public User GetUser(string Loginid, string Password) { Dbcontext db = new Dbcontext(); using (db) { return((from v in db.Users.Include(m => m.Gender).Include(m => m.Role) where v.Loginid.Equals(Loginid) && v.Password.Equals(Password) select v).FirstOrDefault()); } }
/// <summary> /// 根据条件更新 /// </summary> /// <param name="modelModifyProps">要修改的列及修改后列的值集合</param> /// <param name="where">修改的条件</param> /// <returns>返回受影响行数</returns> public int Update <T>(T modelModifyProps, Expression <Func <T, bool> > where) where T : class, new() { int req = -1; //获取符合条件的数据 List <T> list = Dbcontext.Set <T>().Where(where).ToList(); Type t = typeof(T); //得到实体类属性值 List <PropertyInfo> propertyInfos = t.GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList(); //实体-属性集合字典 Dictionary <string, PropertyInfo> dictionaryProps = new Dictionary <string, PropertyInfo>(); //获取实体字段不为空的字段名 string[] paramModifyStrings = new string[propertyInfos.Count]; for (int i = 0; i < propertyInfos.Count; i++) { if (propertyInfos[i].GetValue(modelModifyProps, null) != null) { paramModifyStrings[i] = propertyInfos[i].Name; } } //将实体属性重要修改属性,添加到集合中 Key-属性名 Value-属性对象 propertyInfos.ForEach(p => { if (paramModifyStrings.Contains(p.Name)) { dictionaryProps.Add(p.Name, p); } }); //循环要修改的属性名 foreach (string paramModifyString in paramModifyStrings) { //判断要修改的属性名是否在实体类的属性集合中 if (!string.IsNullOrWhiteSpace(paramModifyString) && dictionaryProps.ContainsKey(paramModifyString)) { //如果存在则去除要修改属性对象 PropertyInfo info = dictionaryProps[paramModifyString]; //取出要修改的值 object newValue = info.GetValue(modelModifyProps, null); //批量设置要修改的对象的属性 foreach (T n in list) { //为要修改的对象的要修改的属性设置新的值 info.SetValue(n, newValue, null); } } } //req = dbcontext.SaveChanges(); req = DbTransaction == null?this.Commit() : 0; return(req); }
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 void DeleteRating(int id) { if (0 >= id) { return; } Dbcontext.UowRepositoryRatings.Delete(id); Dbcontext.Save(); }
public void DeleteUser(int id) { if (0 >= id) { return; } Dbcontext.UowRepositoryUsers.Delete(id); Dbcontext.Save(); }