public bool InsertCompany(b2bCompany model) { //model.CompCode = GenCompCode((int)model.ServiceType,(int)model.emCompID); #region set default model.isNotification = true; model.RowFlag = 2; model.RowVersion = 1; model.CreatedBy = "sa"; model.ModifiedBy = "sa"; model.ModifiedDate = DateTimeNow; model.CreatedDate = DateTimeNow; #endregion if (ValidateInsertCompany()) { qDB.b2bCompanies.InsertOnSubmit(model); qDB.SubmitChanges(); IsResult = true; } else { IsResult = false; } return(IsResult); }
public bool UpdateCompany(b2bCompany model) { var data = qDB.b2bCompanies.Single(q => q.CompID == model.CompID); #region Set Value data = model; data.RowVersion++; data.ModifiedBy = "sa"; data.ModifiedDate = DateTimeNow; #endregion qDB.SubmitChanges(); IsResult = true; return(IsResult); }
public bool RegisterSessionLogon(IEnumerable <view_emCompanyMember> list, b2bCompany model, bool IsOutSource = false) { if (list.Count() > 0) { //ตรวจสอบข้อมูล Cookie ว่ามีการ Login ค้างอยู่ในระบบหรือเปล่า ?? Hashtable htAuthentication = svAuthentication.GetCookieAuthentication(); if (htAuthentication.Count > 0) { //ทำการ Clear ข้อมูลเดิมก่อน UnRegisterSessionLogon(DataManager.ConvertToString(htAuthentication["SessionID"]), DataManager.ConvertToString(htAuthentication["MemberID"])); } //New SessionID string strSessionID = Guid.NewGuid().ToString(); //Add Data To Cookie if (IsOutSource) { AddCookieAuthentication(list, model, strSessionID); } } return(true); }
public ActionResult SignIn(string username, string password, string remember, string admincode) { EncryptManager encrypt = new EncryptManager(); var Url = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext); #region Check Admin var svCompany = new CompanyService(); var sqlWhere = svCompany.CreateWhereAction(Company.CompStatus.Activate); sqlWhere += " AND CompCode = '" + admincode + "' AND ServiceType = 14 "; var companies = svCompany.SelectData <b2bCompany>(" * ", sqlWhere); var company = new b2bCompany(); var isOutSource = false; if (svCompany.TotalRow > 0) { isOutSource = true; foreach (var it in companies) { company.CompCode = it.CompCode; company.DisplayName = it.DisplayName; company.ServiceType = it.ServiceType; } } else { return(Json(new { IsSuccess = false, Result = false })); } #endregion var query = svMember.SelectData <view_emCompanyMember>("MemberID,UserName,Password,DisplayName,Email,CountLogin,CompID", " (UserName ='******' or Email ='" + username + "') and Password ='******' and RowFlagWeb = 2 and IsDelete = 0 and WebID =" + res.Config.WebID, null); List <view_emCompanyMember> list = query; if (svMember.TotalRow > 0) { var data = query.First(); data.CountLogin = data.CountLogin != null ? data.CountLogin : 0; if (data.CountLogin < 500) { #region RegisterSessionLogon(list, company, isOutSource); RegisterRememberLogon(list, Convert.ToBoolean(remember)); if (data.CountLogin != 0) { //Update Count LogOn if (!svMember.UpdateByCondition <emMemberWeb>("CountLogin = 0", "MemberID =" + data.MemberID)) { return(Json(new { IsSuccess = false, Result = "เกิดข้อผิดพลาด กรุณาลองอีกครั้ง" })); } else { return(Json(new { IsSuccess = false, Result = "เกิดข้อผิดพลาด กรุณาลองอีกครั้ง" })); } } else { #region Redirect to HomePage return(Json(new { IsSuccess = true, Result = Url.Action("Index", "Home") })); #endregion } #endregion } else { return(Json(new { IsSuccess = false, Result = Url.Content("คุณเข้าสู่ระบบไม่ผ่าน 5 ครั้ง บัญชีของคุณถูกปิดเพื่อความปลอดภัย กรุณาตรวจสอบอีเมลล์เพื่อยืนยันตัวตน") })); } } else { #region query = svMember.SelectData <view_emCompanyMember>("MemberID,CountLogin,FirstName,LastName,Email,CompID", " (UserName ='******' or Email ='" + username + "') and RowFlagWeb > 1 and WebID =" + res.Config.WebID, null); IEnumerable <view_emCompanyMember> listUser = query.ToList(); if (listUser.Count() > 0) { listUser.First().CountLogin = listUser.First().CountLogin != null?listUser.First().CountLogin : 0; if (listUser.First().CountLogin < 500) { #region if ((4 - listUser.First().CountLogin) == 0) { if (!svMember.UpdateByCondition <emMemberWeb>("CountLogin = 500", "MemberID =" + listUser.First().MemberID)) { return(Json(new { IsSuccess = false, Result = Url.Content("เกิดข้อผิดพลาด กรุณาลองอีกครั้ง") })); } else { if (!svMember.UpdateByCondition <emMemberActivate>("StartDate ='" + DateTime.Now + "',ExpireDate ='" + DateTime.Now.AddHours(24) + "',ActivateType = 3, ActivateCode = '" + emailManager.GenActivateCode() + "'", "MemberID =" + listUser.First().MemberID)) { return(Json(new { IsSuccess = false, Result = Url.Content("เกิดข้อผิดพลาด กรุณาลองอีกครั้ง") })); } else { //if (!SendEmail(listUser)) //{ return(Json(new { IsSuccess = false, Result = Url.Content("เกิดข้อผิดพลาด 5 ครั้ง") })); //} //else // return Json(new { IsSuccess = false, Result = Url.Content("คุณเข้าสู่ระบบไม่ผ่าน 5 ครั้ง บัญชีของคุณถูกปิดเพื่อความปลอดภัย กรุณาตรวจสอบอีเมลล์เพื่อยืนยันตัวตน") }); } } } else { int count = (int)listUser.First().CountLogin + 1; if (!svMember.UpdateByCondition <emMemberWeb>("CountLogin = "******"MemberID =" + listUser.First().MemberID)) { return(Json(new { IsSuccess = false, Result = Url.Content("เกิดข้อผิดพลาด กรุณาลองอีกครั้ง") })); } else { return(Json(new { IsSuccess = false, Result = Url.Content("รหัสผ่านไม่ถูกต้อง คุณสามารถลงชื่อเข้าใช้ได้อีก " + (5 - count) + " ครั้ง") })); } } #endregion } else { return(Json(new { IsSuccess = false, Result = Url.Content("คุณเข้าสู่ระบบไม่ผ่าน 5 ครั้ง บัญชีของคุณถูกปิดเพื่อความปลอดภัย กรุณาตรวจสอบอีเมลล์เพื่อยืนยันตัวตน") })); } } #endregion } return(Json(new { IsSuccess = false, Result = Url.Content("ชื่อผู้ใช้ หรือ Eamil หรือ รหัสผ่านไม่ถูกต้อง") })); }
private void AddCookieAuthentication(IEnumerable <view_emCompanyMember> list, b2bCompany model, string SessionID) { HttpCookie ckAuthentication = new HttpCookie(AppName); var member = list.First(); var company = svCompany.SelectData <b2bCompany>("CompID,CompName,ServiceType,CompCode,CompLevel,DisplayName", "MemberID = " + member.MemberID).First(); ckAuthentication.Values["SessionID"] = SessionID; ckAuthentication.Values["MemberID"] = Convert.ToString(member.MemberID); ckAuthentication.Values["UserName"] = member.UserName; ckAuthentication.Values["DisplayName"] = EncryptText("&%#@?,:*", model.DisplayName); ckAuthentication.Values["Email"] = member.Email; ckAuthentication.Values["emCompID"] = Convert.ToString(member.CompID); ckAuthentication.Values["CompID"] = Convert.ToString(company.CompID); ckAuthentication.Values["ServiceType"] = Convert.ToString(model.ServiceType); ckAuthentication.Values["CompCode"] = Convert.ToString(model.CompCode); ckAuthentication.Values["CompLevel"] = Convert.ToString(company.CompLevel); ckAuthentication.Values["CompName"] = EncryptText("&%#@?,:*", company.CompName); ckAuthentication.Expires = DateTime.Now.AddDays(1); System.Web.HttpContext.Current.Response.Cookies.Add(ckAuthentication); }
public bool InsertCompany(Ouikum.Common.Register model) { b2bCompany data = new b2bCompany(); b2bCompanyProfile compProfile = new b2bCompanyProfile(); if (model.ServiceType < 1 || model.ServiceType == null) { model.ServiceType = 3; } #region set b2bCompany if (model.CompLevel == 0) { model.CompLevel = 1; } data.MemberID = model.MemberID; data.emCompID = model.emCompID; if (model.ServiceType > 0) { data.CompCode = GenCompCode((int)model.ServiceType, (int)model.emCompID).ToString(); } else { data.CompCode = GenCompCode(2, (int)model.emCompID).ToString(); } data.CompLevel = model.CompLevel; if (model.CompLevel == 3) { data.ExpireDate = model.ExpireDate; } data.CompWebsiteTemplate = 0; data.DisplayName = model.DisplayName.Trim(); data.ContactFirstName = model.FirstName_register.Trim(); data.ContactLastName = model.LastName.Trim(); data.ServiceType = DataManager.ConvertToByte(model.ServiceType); data.CompName = model.CompName.Trim(); data.BizTypeID = model.BizTypeID; data.CompCountryID = model.CountryID; data.CompProvinceID = model.ProvinceID; data.CompDistrictID = model.DistrictID; data.CompPhone = model.Phone; data.ContactCountryID = model.CountryID; data.ContactProvinceID = model.ProvinceID; data.ContactDistrictID = model.DistrictID; data.ContactEmail = model.Emails.Trim(); data.ContactPhone = model.Phone; data.FactoryCountryID = model.CountryID; data.FactoryProvinceID = model.ProvinceID; data.FactoryDistrictID = model.DistrictID; data.FactoryPhone = model.Phone; data.IsShow = true; data.CompPostalCode = model.PostalCode; data.ContactPostalCode = model.PostalCode; data.FactoryPostalCode = model.PostalCode; data.CompFax = model.Fax; data.ContactFax = model.Fax; data.FactoryFax = model.Fax; data.ProductCount = 0; data.ViewCount = 0; data.BuyLeadCount = 0; data.isNotification = true; data.IsTrust = DataManager.ConvertToBool(DataManager.ConvertToInteger(model.IsTrust)); data.IsSME = DataManager.ConvertToBool(DataManager.ConvertToInteger(model.IsSME)); if (!string.IsNullOrEmpty(model.BizTypeOther) && model.BizTypeID == 13) { data.BizTypeOther = model.BizTypeOther.Trim(); } #endregion #region set b2bCompanyProfile compProfile.emCompProfileID = model.emCompProfileID; compProfile.CompBizType = (byte)model.BizTypeID; compProfile.CompName = model.CompName.Trim(); compProfile.AddrLine1 = model.AddrLine1; compProfile.CountryID = model.CountryID; compProfile.ProvinceID = model.ProvinceID; compProfile.DistrictID = model.DistrictID; compProfile.PostalCode = model.PostalCode; compProfile.IsShow = true; if (!string.IsNullOrEmpty(compProfile.CompBizTypeOther) && compProfile.CompBizType == 13) { compProfile.CompBizTypeOther = model.BizTypeOther.Trim(); } #endregion using (var trans = new TransactionScope()) { InsertCompany(data); compProfile.CompID = data.CompID; InsertCompanyProfile(compProfile); UpdateCompanySignIn(data.CompID, false); #region Set CompCode ที่ได้ เข้า Register Model กลับไป model.CompCode = data.CompCode; #endregion trans.Complete(); IsResult = true; } return(IsResult); }
public ActionResult editcompany( int compid, string image, string name, string nameeng, string tel, string mobile, string fax, string email, string website, string address, int province, int district ) { var svCompany = new CompanyService(); var svMember = new CompanyService(); var b2bCompany = new b2bCompany(); var emCompanies = new emCompany(); string compimg; string complogo; var Company = svCompany.SelectData <b2bCompany>("*", " CompID = " + compid + ""); b2bCompany = Company.First(); #region set ค่า b2bCompany compimg = b2bCompany.CompImgPath; complogo = b2bCompany.LogoImgPath; b2bCompany.LogoImgPath = image; b2bCompany.CompName = name; b2bCompany.CompNameEng = nameeng; b2bCompany.CompAddrLine1 = address; b2bCompany.CompDistrictID = district; b2bCompany.CompProvinceID = province; b2bCompany.CompPhone = tel; b2bCompany.CompMobile = mobile; b2bCompany.CompWebsiteUrl = website; #endregion #region Update b2bCompany svCompany.SaveData <b2bCompany>(b2bCompany, "CompID"); #endregion if (svCompany.IsResult) { emCompanies = svMember.SelectData <emCompany>("*", " CompID = " + b2bCompany.emCompID).First(); #region set ค่า emCompany emCompanies.LogoImgPath = b2bCompany.LogoImgPath; emCompanies.CompName = b2bCompany.CompName; emCompanies.DisplayName = b2bCompany.DisplayName; emCompanies.CompNameEng = b2bCompany.CompNameEng; emCompanies.CompAddrLine1 = b2bCompany.CompAddrLine1; emCompanies.CompDistrictID = b2bCompany.CompDistrictID; emCompanies.CompProvinceID = b2bCompany.CompProvinceID; emCompanies.CompPostalCode = b2bCompany.CompPostalCode; emCompanies.CompPhone = b2bCompany.CompPhone; emCompanies.CompMobile = b2bCompany.CompMobile; emCompanies.CompFax = b2bCompany.CompFax; emCompanies.BizTypeID = b2bCompany.BizTypeID; emCompanies.BizTypeOther = b2bCompany.BizTypeOther; emCompanies.CompWebsiteUrl = b2bCompany.CompWebsiteUrl; emCompanies.RowVersion = b2bCompany.RowVersion; #endregion #region Update emCompany svMember.SaveData <emCompany>(emCompanies, "CompID"); #endregion if (svCompany.IsResult && svMember.IsResult) { #region SaveLogo if (image != "") { if (b2bCompany.LogoImgPath != complogo) { imgManager = new FileHelper(); //#region Delete Folder //imgManager.DeleteFilesInDir("Companies/Logo/" + b2bCompany.CompID); //#endregion imgManager.DirPath = "Companies/Logo/" + b2bCompany.CompID; imgManager.DirTempPath = "Temp/Companies/Logo/" + b2bCompany.CompID; imgManager.ImageName = image; //imgManager.ImageThumbName = "Thumb_" + form["LogoImgPath"]; imgManager.FullHeight = 150; imgManager.FullWidth = 150; //imgManager.ThumbHeight = 150; //imgManager.ThumbWidth = 150; imgManager.SaveImageFromTemp(); } } #endregion } } return(Json(new { status = svCompany.IsResult }, JsonRequestBehavior.AllowGet)); }