public static string AutoId(WebApiDataEntities db, string Code) { try { Code = Code.ToUpper(); AutoID AutoId = db.AutoIDs.Where(x => x.FCode == Code).SingleOrDefault(); if (AutoId == null) { AutoId = new AutoID(); AutoId.FCode = Code; AutoId.Counter = 1; db.AutoIDs.Add(AutoId); } AutoId.FName = Code; for (int i = 0; i < 6 - AutoId.Counter.ToString().Length; i++) { AutoId.FName += 0; } AutoId.FName += AutoId.Counter.ToString(); AutoId.Counter += 1; db.SaveChanges(); return(AutoId.FName); } catch { return(""); } }
public static void CreateUserLog(WebApiDataEntities db, string TenBang, string ThaoTac, string user) { NhatKySuDung nksd = new NhatKySuDung(); nksd.IdDonVi = GetCurrentDonVi(db, user); nksd.NgayGio = DateTime.Now; nksd.NoiDung = "Người dùng " + user + " đã " + ThaoTac + " dữ liệu trong bảng " + TenBang + " lúc " + DateTime.Now.ToString(); nksd.TenBang = TenBang; nksd.ThaoTac = ThaoTac; nksd.UserName = user; db.NhatKySuDungs.Add(nksd); db.SaveChanges(); }
public static long?GetCurrentDonVi(WebApiDataEntities db, string user) { var oUser = (from u in db.UserProfiles where u.UserName == user select u).FirstOrDefault(); if (oUser != null) { return(oUser.IDDonVi); } else { return(null); } }
public static bool CheckSupperAdmin(WebApiDataEntities db, string user) { var oUser = (from u in db.Group_User join i in db.UserProfiles on u.UserName equals i.UserName where u.CodeGroup == Constants.SUPPERADMIN && u.UserName == user && u.FInUse == true select u ).FirstOrDefault(); if (oUser != null) { return(true); } else { return(false); } }
public async Task <IHttpActionResult> DatLaiMatKhau(string username, string password) { WebApiDataEntities db = new WebApiDataEntities(); ApplicationDbContext context = new ApplicationDbContext(); UserStore <ApplicationUser> store = new UserStore <ApplicationUser>(context); UserManager <ApplicationUser> UserManager = new UserManager <ApplicationUser>(store); //String userId = id; String newPassword = password; String hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword); ApplicationUser cUser = await store.FindByNameAsync(username); await store.SetPasswordHashAsync(cUser, hashedNewPassword); await store.UpdateAsync(cUser); if (!string.IsNullOrEmpty(cUser.Email)) { string email = ConfigurationManager.AppSettings["email"]; string passmail = ConfigurationManager.AppSettings["password"]; using (var mail = new MailMessage(email, cUser.Email)) { string body = "Phần mềm Quản lý Thi đua khen thưởng thông báo : Mật khẩu đặt lại cho tài khoản " + username + " là: " + password; mail.Subject = "Thông báo về đặt lại mật khẩu - Phần mềm Quản lý Thi đua khen thưởng"; mail.Body = body; mail.IsBodyHtml = false; var smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(email, passmail); smtp.Port = 587; smtp.Send(mail); } } return(Ok()); }
public static long?GetLoaiTruong(WebApiDataEntities db, string MaDV) { var dv = (from u in db.DMDonVis where u.MaDonVi == MaDV select u).FirstOrDefault(); return(dv.IDLoaiTruong); }
public string UploadFile() { string ListDinhKem = "#"; try { string directoryPath = HttpContext.Current.Server.MapPath("~/Uploads"); string path1 = Request.RequestUri.GetLeftPart(UriPartial.Authority) + "/Uploads";;// Request.GetRequestContext().VirtualPathRoot;// Request.Url.GetLeftPart(UriPartial.Authority) + "/Uploads"; if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } System.Web.HttpFileCollection httpRequest = System.Web.HttpContext.Current.Request.Files; using (var context = new WebApiDataEntities()) { using (DbContextTransaction transaction = context.Database.BeginTransaction()) { try { for (int i = 0; i <= httpRequest.Count - 1; i++) { string MaDinhKem = ""; MaDinhKem = Auto_ID("FILE"); var oDK = new FILE_DINH_KEM(); System.Web.HttpPostedFile postedfile = httpRequest[i]; if (postedfile.ContentLength > 0) { oDK.FCode = MaDinhKem; oDK.FName = postedfile.FileName; string Filesave = MaDinhKem + postedfile.FileName; if (Filesave.Length > 150) { Filesave = Filesave.Substring(0, 149); } var fileSavePath = Path.Combine(directoryPath, Filesave); if (File.Exists(fileSavePath)) { File.Delete(fileSavePath); } postedfile.SaveAs(fileSavePath); oDK.DuongDanFile = Path.Combine(path1, Filesave);// fileSavePath; if (MaDinhKem != "") { context.FILE_DINH_KEM.Add(oDK); context.SaveChanges(); ListDinhKem = ListDinhKem + MaDinhKem + "#"; } } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); Commons.Common.WriteLogToTextFile(ex.ToString()); } } } } catch (Exception ex) { Commons.Common.WriteLogToTextFile(ex.ToString()); } return(ListDinhKem); }