public Organization AddNewOrganization(CreateOrganization organizationBasic, string UserName) { int CurrenUser = 0; using (var db = new UserDAL()) { CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID; } var newOrg = CreatEmptyOrganization(); newOrg.OrganizationId = CurrenUser; newOrg.OrganizationName = organizationBasic.OrganizationName; newOrg.EOrganizationName = ConvertToUnSign.Convert(organizationBasic.OrganizationName); newOrg.Introduction = organizationBasic.Introduction; newOrg.LogoUrl = organizationBasic.LogoUrl; newOrg.Phone = organizationBasic.Phone; newOrg.Email = organizationBasic.Email; newOrg.Address = organizationBasic.Address; newOrg.IsVerify = false; newOrg.IsActive = true; newOrg.Point = 0; newOrg.CreatedDate = DateTime.Now; using (var db = new Ws_DataContext()) { db.Organizations.Add(newOrg); db.SaveChanges(); return(GetOrganizationById(newOrg.OrganizationId)); } }
public Event AddNewEvent(CreateEventInfo eventInfo, string UserName) { int CurrenUser = 0; using (var db = new UserDAL()) { CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID; } var newEvent = CreateEmptyEvent(); newEvent.CreatorID = GetOrganizationById(CurrenUser).OrganizationId; newEvent.EventType = eventInfo.EventType; newEvent.EventName = eventInfo.EventName; newEvent.EEventName = ConvertToUnSign.Convert(newEvent.EventName); if (eventInfo.StartDate != "") { newEvent.Start_Date = DateTime.Parse(eventInfo.StartDate); } if (eventInfo.FinishDate != "") { newEvent.Finish_Date = DateTime.Parse(eventInfo.FinishDate); } newEvent.ShortDescription = eventInfo.ShortDescription; newEvent.Location = eventInfo.Location; newEvent.ExpectedMoney = eventInfo.ExpectedMoney; newEvent.Description = eventInfo.Content; newEvent.Contact = eventInfo.Contact; newEvent.VideoUrl = eventInfo.VideoUrl; using (var db = new Ws_DataContext()) { db.Events.Add(newEvent); db.SaveChanges(); return(GetEventById(newEvent.EventID)); } }
public bool UpdateUserInfo(UserBasicInfoDTO UserInfo, string userName) { try { using (var db = new Ws_DataContext()) { var newInformation = db.User_Information.Where(x => x.Ws_User.UserName == userName).SingleOrDefault(); if (UserInfo.FullName != null) { newInformation.FullName = UserInfo.FullName; newInformation.EFullName = ConvertToUnSign.Convert(UserInfo.FullName); } if (UserInfo.Phone != null) { newInformation.Phone = UserInfo.Phone; } if (UserInfo.Address != null) { newInformation.UserAddress = UserInfo.Address; newInformation.EUserAddress = ConvertToUnSign.Convert(UserInfo.Address); } if (UserInfo.Country != null) { newInformation.Country = UserInfo.Country; } if (UserInfo.Gender != null) { newInformation.Gender = UserInfo.Gender; } if (UserInfo.DOB != "") { newInformation.DoB = Convert.ToDateTime(UserInfo.DOB); } if (UserInfo.FacebookUri != null) { newInformation.FacebookUrl = UserInfo.FacebookUri; } if (UserInfo.UserSignature != null) { newInformation.UserSignature = UserInfo.UserSignature; } db.User_Information.AddOrUpdate(newInformation); db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
public ActionResult Create(Category cate) { if (ModelState.IsValid) { var dao = new CategoryDAO(); cate.MetaTitle = ConvertToUnSign.utf8Convert(cate.CategoryName); long id = dao.Insert(cate); if (id > 0) { return(RedirectToAction("Index", "Category")); } else { ModelState.AddModelError("", "Thêm không thành công"); } } return(View(cate)); }
public ActionResult Edit(Category proCate) { if (ModelState.IsValid) { var DAO = new CategoryDAO(); proCate.MetaTitle = ConvertToUnSign.convertunsign(proCate.MetaTitle); var result = DAO.Update(proCate); if (result) { SetAlert("Cập nhật thành công", "success"); return(RedirectToAction("Index", "Category")); } else { SetAlert("Cập nhật thất bại", "error"); ModelState.AddModelError("", "Cập nhật thất bại"); } } return(View("Index")); }
public ActionResult Create(Category proCate) { if (ModelState.IsValid) { var DAO = new CategoryDAO(); proCate.MetaTitle = ConvertToUnSign.convertunsign(proCate.MetaTitle); proCate.CreatedDate = DateTime.Now; long id = DAO.Insert(proCate); if (id > 0) { SetAlert("Thêm thành công", "success"); return(RedirectToAction("Index", "Category")); } else { SetAlert("Thêm thất bại", "error"); ModelState.AddModelError("", "Thêm thất bại"); } } return(View("Index")); }
public ActionResult Create(Post post) { if (ModelState.IsValid) { var dao = new PostDAO(); post.MetaTitle = ConvertToUnSign.utf8Convert(post.Title); post.DatetimeCreate = DateTime.Now; long id = dao.Insert(post); if (id > 0) { return(RedirectToAction("Index", "Post")); } else { ModelState.AddModelError("", "Thêm không thành công"); } } SetViewBag(); return(View(post)); }
public ActionResult Edit(Content content) { if (ModelState.IsValid) { var DAO = new ContentDAO(); content.MetaTitle = ConvertToUnSign.convertunsign(content.MetaTitle); var result = DAO.Update(content); if (result) { SetAlert("Cập nhật thành công", "success"); return(RedirectToAction("Index", "Content")); } else { SetAlert("Cập nhật thất bại", "error"); ModelState.AddModelError("", "Cập nhật thất bại"); } } SetViewBag(content.CategoryID); return(View("Index")); }
public ActionResult Edit(Menu menu) { if (ModelState.IsValid) { var DAO = new MenuDAO(); menu.Link = ConvertToUnSign.convertunsign(menu.Link); var result = DAO.Update(menu); if (result) { SetAlert("Cập nhật thành công", "success"); return(RedirectToAction("Index", "Menu")); } else { SetAlert("Cập nhật thất bại", "error"); ModelState.AddModelError("", "Cập nhật thất bại"); } } return(View("Index")); }
public ActionResult Create(Menu menu) { if (ModelState.IsValid) { var DAO = new MenuDAO(); menu.Link = ConvertToUnSign.convertunsign(menu.Link); long id = DAO.Insert(menu); if (id > 0) { SetAlert("Thêm thành công", "success"); return(RedirectToAction("Index", "Menu")); } else { SetAlert("Thêm thất bại", "error"); ModelState.AddModelError("", "Thêm thất bại"); } } return(View("Index")); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { var DAO = new ProductDAO(); product.MetaTitle = ConvertToUnSign.convertunsign(product.MetaTitle); long id = DAO.Insert(product); if (id > 0) { SetAlert("Thêm thành công", "success"); return(RedirectToAction("Index", "Product")); } else { SetAlert("Thêm thất bại", "error"); ModelState.AddModelError("", "Thêm thất bại"); } } SetViewBag(); return(View("Index")); }
public ActionResult Edit(Category cate) { if (ModelState.IsValid) { var dao = new CategoryDAO(); // chuyen thanh chuoi khong dau // gan cho field Metatile cate.MetaTitle = ConvertToUnSign.utf8Convert(cate.CategoryName); var result = dao.Update(cate); if (result) { return(RedirectToAction("Index", "Category")); } else { ModelState.AddModelError("", "Cập nhật không thành công"); } } return(View(cate)); }
public Thread AddNewThread(CreateThreadInfo thread, string UserName) { int CurrenUser = 0; using (var db = new UserDAL()) { CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID; } var newThread = CreateEmptyThread(); newThread.UserId = CurrenUser; newThread.Title = thread.Title; newThread.Etitle = ConvertToUnSign.Convert(thread.Title); newThread.Content = thread.Content; newThread.ShortDescription = thread.ShortDescription; using (var db = new Ws_DataContext()) { db.Threads.Add(newThread); db.SaveChanges(); return(GetThreadById(newThread.ThreadId)); } }
public Ws_User RegisterFacebook(dynamic me) { string email = me.email; // Create new User var newUser = new Ws_User { Email = email, CreatedDate = DateTime.UtcNow, IsActive = true, UserPassword = string.Empty, IsVerify = true, LastLogin = DateTime.UtcNow, AccountType = false, UserName = "******" + email.Split(new string[] { "@" }, StringSplitOptions.None)[0], VerifyCode = string.Empty, User_Information = new User_Information { UserAddress = me.location, FullName = me.name, EFullName = ConvertToUnSign.Convert(me.name), Gender = me.gender, DoB = (Convert.ToDateTime(me.birthday) != DateTime.MinValue)?Convert.ToDateTime(me.birthday):null, FacebookUrl = me.link, ProfileImage = "https://graph.facebook.com/" + me.id + "/picture?type=large", Country = string.Empty, Phone = string.Empty, OrgnazationIDFollow = string.Empty, UserSignature = string.Empty, Point = 0 } }; // Facebook account // insert user to Database newUser = AddNewUser(newUser); return(newUser); }
public ActionResult Edit(Post post) { if (ModelState.IsValid) { var dao = new PostDAO(); // chuyen sang chuoi khong dau // gan vao cho metatitle post.MetaTitle = ConvertToUnSign.utf8Convert(post.Title); var result = dao.Update(post); if (result) { return(RedirectToAction("Index", "Post")); } else { ModelState.AddModelError("", "Cập nhật không thành công"); } } SetViewBag(post.CategoryID); return(View(post)); }
public ActionResult Register(UserRegisterDTO account) { try { //Save data to database Random rnd = new Random(); var verifycode = rnd.Next(000001, 999999).ToString(); var Md5pass = MD5Helper.MD5Encrypt(account.PassWord); var newUser = new Ws_User { Email = account.Email, UserName = account.UserName, UserPassword = Md5pass, CreatedDate = DateTime.UtcNow, IsActive = true, IsVerify = false, AccountType = false, VerifyCode = verifycode, User_Information = new User_Information { ProfileImage = "Content/Images/avatar_default.png", FullName = account.FullName, EFullName = ConvertToUnSign.Convert(account.FullName) } }; using (var userDal = new UserDAL()) { userDal.AddNewUser(newUser); } // Send Verify code //khai báo biến để gửi mã xác nhận var fromAddress = new MailAddress(WsConstant.VerifyEmail.AdminEmail, WsConstant.VerifyEmail.WsOrganization); var toAddress = new MailAddress(account.Email, account.UserName); string fromPassword = WsConstant.VerifyEmail.AdminEmailPass; string subject = WsConstant.VerifyEmail.EmailSubject; string body = WsConstant.VerifyEmail.EmailContentFirst + " Tên đăng nhập : " + account.UserName + "\n Mã xác nhận : " + verifycode + WsConstant.VerifyEmail.EmailContentLast; //xu li gui mail var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } //chuyển đến trang đăng ký thành công return(Redirect("/#/RegisterSuccess")); } catch (Exception ex) { ViewBag.ErrorMessage = ex; return(Redirect("/#/Error")); } }