public ActionResult Update(int id, string ParentID) { var model = menuBarSrv.Getbykey(id); try { TryUpdateModel <Menu>(model); var c = menuBarSrv.Query.Where(p => (p.Id != id) && (p.NameVNI == model.NameVNI || p.NameENG == model.NameENG || p.NavigateUrl == model.NavigateUrl)).Count(); if (c > 0) { ViewData["MenuParents"] = menuBarSrv.Query.Where(p => p.ParentID == 0).OrderBy(p => p.NameVNI).ToList(); Messages.AddErrorMessage("Tiêu đề hoặc đường dẫn đã tồn tại"); return(View("Edit", model)); } model.ParentID = !string.IsNullOrWhiteSpace(ParentID) ? int.Parse(ParentID) : 0; if (model.ParentID != 0) { Menu menubar = menuBarSrv.Getbykey(model.ParentID); if (model.Position != menubar.Position) { model.Position = menubar.Position; } } menuBarSrv.Save(model); menuBarSrv.CommitChanges(); Messages.AddFlashMessage("Sửa đổi thành công"); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Menu - Update : " + id, "Update Menu Success ", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(RedirectToAction("Index")); } catch (Exception ex) { ViewData["MenuParents"] = menuBarSrv.Query.Where(p => p.ParentID == 0).OrderBy(p => p.NameVNI).ToList(); Messages.AddErrorMessage("Có lỗi trong quá trình xử lý, vui lòng thực hiện lại."); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Menu - Update : " + id, "Update Menu Error " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(View("Edit", model)); } }
public ActionResult Update(int id) { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; if (id != _currentCompany.id) { return(Redirect("/Home/PotentiallyError")); } ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company model = _comSrv.Getbykey(_currentCompany.id); try { TryUpdateModel <Company>(model); model.TaxCode = Utils.formatTaxcode(model.TaxCode); _comSrv.Save(model); _comSrv.CommitChanges(); Messages.AddFlashMessage(Resources.Message.Com_UMesInfSuccess); log.Info("Update Company: " + HttpContext.User.Identity.Name); return(RedirectToAction("DetailCurrent")); } catch (HttpRequestValidationException ex) { return(Redirect("/Home/PotentiallyError")); } catch (ArgumentException ex) { return(Redirect("/Home/PotentiallyError")); } catch (Exception ex) { Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); log.Error("Error Update-" + ex); ITaxAuthorityService _taxSvc = IoC.Resolve <ITaxAuthorityService>(); IList <TaxAuthority> tax = _taxSvc.GetAll(); ViewData["tax"] = tax; return(View("Edit", model)); } }
public ActionResult CreateRole(RoleModel model, string[] permissions) { IroleService _RoleSrc = IoC.Resolve <IroleService>(); IpermissionService _PermissionSrc = IoC.Resolve <IpermissionService>(); IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); try { int cRole = _RoleSrc.Query.Where(p => p.AppID == _MemberShipProvider.Application.AppID && p.name.ToUpper() == model.name.Trim().ToUpper()).Count(); if (cRole > 0) { Messages.AddErrorMessage("Tên quyền này đã tồn tại trong hệ thống."); List <permission> lPermissions = _PermissionSrc.Query.Where(a => a.AppID == _MemberShipProvider.Application.AppID).ToList <permission>(); ViewData["Permissions"] = lPermissions; model.Permissions = new List <permission>(); return(View("Create", model)); } role omodel = new role(); model.Permissions = permissions == null ? new List <permission>() : _PermissionSrc.Query.Where(p => permissions.Contains(p.name)).OrderBy(p => p.Description).ToList <permission>(); //lay cac thong tin cho role omodel.name = model.name; omodel.Permissions = model.Permissions; omodel.AppID = _MemberShipProvider.Application.AppID; _RoleSrc.CreateNew(omodel); _RoleSrc.CommitChanges(); Messages.AddFlashMessage("Tạo quyền thành công."); log.Info("Create Role by:" + HttpContext.User.Identity.Name + " Info-- NameRole " + model.name); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error("Create Role-" + ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); List <permission> lPermissions = _PermissionSrc.Query.Where(a => a.AppID == _MemberShipProvider.Application.AppID).OrderBy(p => p.Description).ToList <permission>(); ViewData["Permissions"] = lPermissions; model.Permissions = new List <permission>(); return(View("Create", model)); } }
public ActionResult Create(Banners model) { try { model.CreatedBy = HttpContext.User.Identity.Name; model.CreatedDate = DateTime.Now; model.ModifiedDate = DateTime.Now; model.FromDate = DateTime.Now; model.ToDate = DateTime.MaxValue; bannerSrv.CreateNew(model); bannerSrv.CommitChanges(); Messages.AddFlashMessage("Tạo mới banner thành công"); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Banner - Create :" + model.Id, "Create Banner Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(RedirectToAction("Index")); } catch (Exception e) { logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Banner - Create :" + model.Id, "Create Banner Error: " + e.Message, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); Messages.AddErrorMessage("Có lỗi trong quá trình xử lý, vui lòng thực hiện lại."); return(View(model)); } }
public ActionResult UpdatePasswordCustomer(string username, string newPassword, string confirmPassword) { IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); user userCustomer = _MemberShipProvider.GetUser(username, true); if (userCustomer == null) { Messages.AddErrorFlashMessage("Tài khoản không có trên hệ thống."); return(RedirectToAction("Index", "Customer")); } try { if (newPassword == confirmPassword) { userCustomer.PasswordSalt = GeneratorPassword.GenerateSalt(); userCustomer.password = GeneratorPassword.EncodePassword(newPassword, userCustomer.PasswordFormat, userCustomer.PasswordSalt); _MemberShipProvider.UpdateUser(userCustomer); Messages.AddFlashMessage(Resources.Message.User_MesChangePasswordSuccess); } else { Messages.AddErrorMessage(Resources.Message.User_MesErrConfirmPass); ChangePasswordModel model = new ChangePasswordModel(); model.username = username; return(View(model)); } return(RedirectToAction("Index", "Customer")); } catch (Exception ex) { log.Error("Error", ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); ChangePasswordModel model = new ChangePasswordModel(); model.username = username; return(View("ChangePasswordCustomer", model)); } }
public ActionResult Create(Menu model) { try { var c = menuBarSrv.Query.Where(p => p.NameVNI == model.NameVNI || p.NameENG == model.NameENG || p.NavigateUrl == model.NavigateUrl).Count(); if (c > 0) { ViewData["MenuParents"] = menuBarSrv.Query.Where(p => p.ParentID == 0).OrderBy(p => p.NameVNI).ToList(); Messages.AddErrorMessage("Tiêu đề hoặc đường dẫn đã tồn tại"); return(View(model)); } if (model.ParentID != 0) { Menu menubar = menuBarSrv.Getbykey(model.ParentID); if (model.Position != menubar.Position) { model.Position = menubar.Position; } } model.CreatedDate = DateTime.Now; menuBarSrv.CreateNew(model); menuBarSrv.CommitChanges(); Messages.AddFlashMessage("Tạo mới menu thành công"); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Menu - Create : " + model.Id, "Create Menu Success ", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(RedirectToAction("Index")); } catch (Exception ex) { logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Menu - Create : " + model.Id, "Create Menu Error " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); ViewData["MenuParents"] = menuBarSrv.Query.Where(p => p.ParentID == 0).OrderBy(p => p.NameVNI).ToList(); Messages.AddErrorMessage("Có lỗi trong quá trình xử lý, vui lòng thực hiện lại."); return(View(model)); } }
public ActionResult Create(Products model) { try { var pro = _proSvc.Query.Where(i => i.Code.ToUpper() == model.Code.Trim().ToUpper() && i.ComID == _currentCompany.id); if (pro.Count() > 0) { Messages.AddErrorMessage(Resources.Message.Prod_IMesCodeExits); return(View(model)); } model.ComID = _currentCompany.id; _proSvc.Save(model); _proSvc.CommitChanges(); Messages.AddFlashMessage(Resources.Message.Prod_IMesSuccess); log.Info("Create Products by: " + HttpContext.User.Identity.Name); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error(" Create -" + ex); Messages.AddErrorMessage(Resources.Message.Prod_IMesUnsuccess); return(View(model)); } }
public ActionResult Update(int id) { if (id <= 0) { throw new HttpRequestValidationException(); } Products model = _proSvc.Getbykey(id); try { TryUpdateModel <Products>(model); _proSvc.Save(model); _proSvc.CommitChanges(); log.Info("Edit Product by: " + HttpContext.User.Identity.Name); Messages.AddFlashMessage(Resources.Message.Prod_UMesSuccess); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error(" Edit -" + ex); Messages.AddErrorMessage(Resources.Message.Prod_UMesUnsuccess); return(View("Edit", model)); } }
public ActionResult Edit(int id, CustomerModel model, string[] DeliverMethod) { if (id <= 0) { throw new HttpRequestValidationException(); } ICustomerService cusSrv = IoC.Resolve <ICustomerService>(); Company _currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; string ErroMessage = ""; Customer oCus = cusSrv.Getbykey(id); try { TryUpdateModel <Customer>(oCus); if (!string.IsNullOrWhiteSpace(oCus.TaxCode)) { if (cusSrv.Query.Where(p => p.TaxCode.ToUpper() == oCus.TaxCode.ToUpper() && p.id != oCus.id).Count() > 0) { model.tmpCustomer = oCus; Messages.AddErrorMessage("Mã số thuế đã tồn tại trên hệ thống!"); return(View("Edit", model)); } oCus.TaxCode = Utils.formatTaxcode(oCus.TaxCode); } if (DeliverMethod == null) { oCus.DeliverMethod = -1; } else if (DeliverMethod.Length == 1) { if (DeliverMethod[0] == "0") { oCus.DeliverMethod = 0; } else if (DeliverMethod[0] == "1") { oCus.DeliverMethod = 1; } } else if (DeliverMethod.Length == 2) { oCus.DeliverMethod = 2; } //end delivermethod Certificate cer = model.UpdateCertificate(new Certificate()); if (cusSrv.UpdateCus(oCus, cer, _currentCom.id, out ErroMessage) == true) { log.Info("Edit Customer by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + oCus.Name + " TaiKhoanKhachHang: " + oCus.AccountName + " Email: " + oCus.Email); Messages.AddFlashMessage(Resources.Message.Cus_UMesSuccess); } else { model.tmpCustomer = oCus; Messages.AddErrorMessage(ErroMessage); return(View(model)); } return(RedirectToAction("Index")); } catch (Exception ex) { log.Error(ex); model.tmpCustomer = oCus; Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); return(View(model)); } }
public ActionResult Edit(string Pattern, int id, string PubDatasource) { if (id <= 0) { throw new HttpRequestValidationException(); } ICompanyService comSrv = IoC.Resolve <ICompanyService>(); Company currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>(); IRegisterTempService _ReTemSvc = IoC.Resolve <IRegisterTempService>(); IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id); IInvoice model = IInvSrv.Getbykey <IInvoice>(id); string NoteOrder = model.Note; try { string ErrorMessage = ""; TryUpdateModelFromType(model.GetType(), model); model.CusCode = !string.IsNullOrWhiteSpace(model.CusCode) ? model.CusCode : model.CusTaxCode; model.Note = NoteOrder + " || " + model.Note; if (!String.IsNullOrEmpty(PubDatasource) && PubDatasource != "[]") { ICustomerService _CusSvc = FX.Core.IoC.Resolve <ICustomerService>(); var Typecus = (from c in _CusSvc.Query where c.Code == model.CusCode && c.CusType == 1 select c.CusType).FirstOrDefault(); if (Typecus == 0) { model.CusSignStatus = cusSignStatus.NocusSignStatus; } else { model.CusSignStatus = cusSignStatus.NoSignStatus; } IList <ProductInv> lstproduct = (IList <ProductInv>)PubDatasource.DeserializeJSON <ProductInv>(typeof(IList <ProductInv>)); if (IInvSrv.UpdateInvoice(lstproduct, model, out ErrorMessage) == true) { log.Info("Edit EInvoice by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount); Messages.AddFlashMessage("Cập nhật hóa đơn thành công."); return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial })); } else { Messages.AddErrorMessage(ErrorMessage); } model.Products = (from pr in lstproduct select pr as IProductInv).ToList(); } else { Messages.AddErrorMessage("Chưa nhập thông tin sản phẩm"); } model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id); List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id); ViewData["ser"] = ser; ViewData["company"] = currentCom; string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit"; return(View(ViewName, model)); } catch (HttpRequestValidationException ex) { log.Error("ArgumentException: " + ex); Messages.AddErrorMessage("Dữ liệu không hợp lệ hoặc có chứa mã gây nguy hiểm tiềm tàng cho hệ thống!"); model = IInvSrv.Getbykey <IInvoice>(id); List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id); ViewData["ser"] = ser; ViewData["company"] = currentCom; string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit"; return(View(ViewName, model)); } catch (Exception ex) { log.Error("Edit -", ex); model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id); List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id); ViewData["ser"] = ser; ViewData["company"] = currentCom; Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại"); if (!String.IsNullOrEmpty(PubDatasource)) { IList <ProductInv> lstproduct = (IList <ProductInv>)PubDatasource.DeserializeJSON <ProductInv>(typeof(IList <ProductInv>)); model.Products = (from pr in lstproduct select pr as IProductInv).ToList(); } string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit"; return(View(ViewName, model)); } }
public ActionResult CancelInvNotReIndex(EInvoiceIndexModel model, int?page, int?Pagesize) { IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>(); Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IList <string> lstpattern = _PubIn.LstByPattern(currentCom.id, 1); if (lstpattern.Count == 0) { Messages.AddErrorFlashMessage(Resources.Message.MInv_SMesNoPubAccess); return(RedirectToAction("Index", "Home")); } if (model == null) { model = new EInvoiceIndexModel(); } //lay pattern if (string.IsNullOrEmpty(model.Pattern)) { model.Pattern = lstpattern[0]; } model.lstpattern = lstpattern; //lay serial List <string> LstSerial = (from p in _PubIn.Query where p.Status != 0 && p.InvPattern == model.Pattern && p.ComId == currentCom.id select p.InvSerial).Distinct().ToList <string>(); model.lstserial = LstSerial; if (string.IsNullOrEmpty(model.Serial)) { model.Serial = LstSerial[0]; } int defautPagesize = Pagesize.HasValue ? Convert.ToInt32(Pagesize) : 10; int currentPageIndex = page.HasValue ? page.Value - 1 : 0; int totalRecords = 0; IInvoiceService IInvSrv = InvServiceFactory.GetService(model.Pattern, currentCom.id); IList <IInvoice> lst; if (!model.InvNo.HasValue) { DateTime?DateFrom = null; DateTime?DateTo = null; if (!string.IsNullOrWhiteSpace(model.FromDate)) { DateFrom = DateTime.ParseExact(model.FromDate, "dd/MM/yyyy", null); } if (!string.IsNullOrWhiteSpace(model.ToDate)) { DateTo = DateTime.ParseExact(model.ToDate, "dd/MM/yyyy", null); } if (DateFrom != null && DateTo != null && DateFrom > DateTo) { Messages.AddErrorMessage("Nhập đúng dữ liệu tìm kiếm theo ngày!"); DateFrom = DateTo = null; } InvoiceStatus[] status = new InvoiceStatus[] { InvoiceStatus.SignedInv, InvoiceStatus.AdjustedInv, InvoiceStatus.ReplacedInv, InvoiceStatus.InUseInv }; lst = IInvSrv.SearchByStatus(currentCom.id, model.Pattern, model.Serial, DateFrom, DateTo, model.nameCus, model.code, model.CodeTax, (InvoiceType)model.typeInvoice, currentPageIndex, defautPagesize, out totalRecords, status); } else { lst = new List <IInvoice>(); IInvoice inv = IInvSrv.GetByNo(currentCom.id, model.Pattern, model.Serial, model.InvNo.Value); if (inv != null) { lst.Add(inv); } totalRecords = lst.Count(); } model.PageListINV = new PagedList <IInvoice>(lst, currentPageIndex, defautPagesize, totalRecords); return(View(model)); }
public ActionResult Create(user _model, string RetypePassword, string[] AssignRoles) { IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); IuserService _userService = IoC.Resolve <IuserService>(); IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); AccountModels model = new AccountModels(); if (string.IsNullOrWhiteSpace(_model.username)) { Messages.AddErrorMessage("Cần nhập những thông tin bắt buộc."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); model.RetypePassword = _model.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = AssignRoles ?? new string[] { }; model.tmpUser = _model; return(View("New", model)); } try { string status = ""; AssignRoles = AssignRoles ?? new string[] { }; if (!_model.password.Equals(RetypePassword)) { Messages.AddErrorMessage("Nhập đúng mật khẩu của bạn."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); model.RetypePassword = _model.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = new string[] { }; model.tmpUser = _model; return(View("New", model)); } else { _MemberShipProvider.CreateUser(_model.username, _model.password, _model.email, _model.PasswordQuestion, _model.PasswordAnswer, _model.IsApproved, null, out status); if (status != "Success") { List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); model.RetypePassword = _model.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = new string[] { }; model.tmpUser = _model; Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ."); return(View("New", model)); } if (AssignRoles == null) { Messages.AddFlashMessage("Bạn tạo tài khoản thành công nhưng chưa phân quyền!"); return(RedirectToAction("index")); } _RoleProvider.UpdateUsersToRoles(_model.username, AssignRoles); Messages.AddFlashMessage("Tạo tài khoản thành công."); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "User - Create : " + string.Format("Create: {0} by {1}", _model.username, HttpContext.User.Identity.Name), "Create User Success ", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(RedirectToAction("index")); } } catch (Exception ex) { logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "User - Create ", "Create User Error: " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); Messages.AddErrorMessage("Chưa tạo được người dùng."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); model.RetypePassword = _model.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = new string[] { }; model.tmpUser = _model; return(View("New", model)); } }
public ActionResult Index(EInvoiceIndexModel model, int?page, int?Pagesize) { IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>(); Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; try { IList <string> lstpattern = _PubIn.LstByPattern(currentCom.id, 1); if (lstpattern.Count == 0) { Messages.AddErrorFlashMessage("Cần tạo thông báo phát hành."); return(RedirectToAction("Index", "Publish")); } if (model == null) { model = new EInvoiceIndexModel(); } model.Pattern = string.IsNullOrEmpty(model.Pattern) ? lstpattern[0] : model.Pattern; model.lstpattern = lstpattern; List <string> LstSerial = _PubIn.ListSerialByPattern(currentCom.id, model.Pattern, new int[] { 1, 2, 3 }).Distinct().ToList <string>(); model.lstserial = LstSerial; int defautPagesize = Pagesize.HasValue ? Convert.ToInt32(Pagesize) : 10; int currentPageIndex = page.HasValue ? page.Value - 1 : 0; int totalRecords = 0; IInvoiceService IInvSrv = InvServiceFactory.GetService(model.Pattern, currentCom.id); IList <IInvoice> lst; if (!model.InvNo.HasValue || model.InvNo == null) { DateTime?DateFrom = null; DateTime?DateTo = null; if (!string.IsNullOrWhiteSpace(model.FromDate)) { DateFrom = DateTime.ParseExact(model.FromDate, "dd/MM/yyyy", null); } if (!string.IsNullOrWhiteSpace(model.ToDate)) { DateTo = DateTime.ParseExact(model.ToDate, "dd/MM/yyyy", null); } if (DateFrom != null && DateTo != null && DateFrom > DateTo) { Messages.AddErrorMessage("Nhập đúng dữ liệu tìm kiếm theo ngày!"); DateFrom = DateTo = null; } lst = IInvSrv.SearchByCustomer(currentCom.id, model.Pattern, model.Serial, DateFrom, DateTo, (InvoiceStatus)model.Status, model.nameCus, model.code, model.CodeTax, (InvoiceType)model.typeInvoice, currentPageIndex, defautPagesize, out totalRecords); } else { lst = IInvSrv.GetListByNo(currentCom.id, model.Pattern, model.Serial, model.InvNo.Value); totalRecords = lst.Count(); } model.PageListINV = new PagedList <IInvoice>(lst, currentPageIndex, defautPagesize, totalRecords); int signPlugin = 0; if (currentCom.Config.Keys.Contains("SignPlugin")) { int.TryParse(currentCom.Config["SignPlugin"], out signPlugin); } model.SignPlugin = signPlugin; return(View(model)); } catch (UnAuthorizedException e) { log.Error(e); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); return(RedirectToAction("Index", "Home")); } catch (ArgumentException ex) { log.Error(ex); return(Redirect("/Home/PotentiallyError")); } catch (HttpRequestValidationException ex) { log.Error(ex); return(RedirectToAction("PotentiallyError", "Home")); } }
public ActionResult Create(RegisterTemp temp, string actionName, int tempId) { HttpPostedFileBase logoImg = Request.Files["logoImg"]; HttpPostedFileBase bgrImg = Request.Files["bgrImg"]; string _logoFile = Request["logoFile"]; string _imgFile = Request["imgFile"]; Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvTemplateService tempSrv = IoC.Resolve <IInvTemplateService>(); IRegisterTempService regisTempSrv = IoC.Resolve <IRegisterTempService>(); string registerPattern = temp.InvPattern + "/" + temp.PatternOrder.ToString("000"); if (regisTempSrv.Query.Where(p => p.InvPattern.ToUpper() == registerPattern.ToUpper() && p.ComId == temp.ComId).Count() > 0) { Messages.AddErrorMessage(string.Format("Mẫu số [{0}] đã được đăng ký cho công ty.", registerPattern)); RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; return(View(model)); } try { InvTemplate invTemp = tempSrv.Getbykey(tempId); temp.InvoiceTemp = invTemp; string logoKey = string.Format("{0}_{1}", currentCom.id, "logo"); string backgroudKey = string.Format("{0}_{1}", currentCom.id, "backgroud"); if (logoImg != null && logoImg.ContentLength > 0) { byte[] byteLogoImg = readContentFilePosted(logoImg); setCacheContext(logoKey, updateCss(invTemp.CssLogo, byteLogoImg)); } if (string.IsNullOrWhiteSpace(_logoFile) && !string.IsNullOrWhiteSpace(invTemp.CssLogo)) { setCacheContext(logoKey, invTemp.CssLogo); } if (bgrImg != null && bgrImg.ContentLength > 0) { byte[] bytebgrImg = readContentFilePosted(bgrImg); setCacheContext(backgroudKey, updateCss(invTemp.CssBackgr, bytebgrImg, false)); } if (string.IsNullOrWhiteSpace(_imgFile) && !string.IsNullOrWhiteSpace(invTemp.CssBackgr)) { setCacheContext(backgroudKey, invTemp.CssBackgr); } temp.CssData = !string.IsNullOrWhiteSpace(temp.CssData) ? temp.CssData : invTemp.CssData; if (actionName == "preview") { RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; model.imgFile = _imgFile; model.logoFile = _logoFile; StringBuilder sumSb = new StringBuilder(); sumSb.AppendFormat("{0}{1}{2}", temp.CssData, getCacheContext(logoKey), getCacheContext(backgroudKey)); XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.LoadXml(invTemp.XmlFile); if (xdoc.GetElementsByTagName("ComName")[0] != null) { xdoc.GetElementsByTagName("ComName")[0].InnerText = currentCom.Name; } if (xdoc.GetElementsByTagName("ComAddress")[0] != null) { xdoc.GetElementsByTagName("ComAddress")[0].InnerText = currentCom.Address; } if (xdoc.GetElementsByTagName("ComPhone")[0] != null) { xdoc.GetElementsByTagName("ComPhone")[0].InnerText = currentCom.Phone; } if (xdoc.GetElementsByTagName("ComBankNo")[0] != null) { //xdoc.GetElementsByTagName("ComFax")[0].InnerText = comFax; xdoc.GetElementsByTagName("ComBankNo")[0].InnerText = currentCom.BankNumber; } if (xdoc.GetElementsByTagName("ComTaxCode")[0] != null) { xdoc.GetElementsByTagName("ComTaxCode")[0].InnerText = currentCom.TaxCode; } XmlNode root = xdoc.DocumentElement; //Create a new node. XmlElement elem = xdoc.CreateElement("CssData"); elem.InnerText = sumSb.ToString(); //Add the node to the document. root.AppendChild(elem); XmlProcessingInstruction newPI; String PItext = "type='text/xsl' href='" + FX.Utils.UrlUtil.GetSiteUrl() + "/RegisterTemp/getXSLTbyTempName?tempname=" + invTemp.TemplateName + "'"; newPI = xdoc.CreateProcessingInstruction("xml-stylesheet", PItext); xdoc.InsertBefore(newPI, xdoc.DocumentElement); IViewer _iViewerSrv = InvServiceFactory.GetViewer(invTemp.TemplateName); ViewData["previewContent"] = _iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(xdoc.OuterXml)); return(View(model)); } temp.ICertifyProvider = temp.IsCertify ? temp.ICertifyProvider : ""; temp.InvPattern = registerPattern; if (regisTempSrv.GetbyPattern(temp.InvPattern, currentCom.id) != null) { Messages.AddErrorFlashMessage("Mẫu số đã được đăng ký, sử dụng mẫu số khác!"); RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; model.imgFile = _imgFile; model.logoFile = _logoFile; return(View(model)); } temp.ComId = currentCom.id; temp.InvCateID = invTemp.InvCateID; temp.CssLogo = getCacheContext(logoKey); temp.CssBackgr = getCacheContext(backgroudKey); regisTempSrv.CreateNew(temp); regisTempSrv.CommitChanges(); Messages.AddFlashMessage("Đăng ký mẫu hóa đơn thành công!"); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error(ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; model.imgFile = _imgFile; model.logoFile = _logoFile; return(View(model)); } }
public ActionResult CreateRPublish(Publish mPub, string PubInvoiceList) { IPublishService pubSrc = IoC.Resolve <IPublishService>(); ITaxAuthorityService taxSrv = IoC.Resolve <ITaxAuthorityService>(); ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); string message = ""; try { mPub.TaxAuthorityName = (from tax in taxSrv.Query where tax.Code == mPub.TaxAuthorityCode select tax.Name).FirstOrDefault(); JavaScriptSerializer jss = new JavaScriptSerializer(); IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); foreach (var it in lst) { IPublishInvoiceService pubinvSrv = IoC.Resolve <IPublishInvoiceService>(); string invSer = string.Format("{0}/{1}E", it.InvSerialPrefix, it.InvSerialSuffix); var old = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate > it.StartDate && p.ComId == _currentcompany.id).FirstOrDefault(); if (old != null) { Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu sau ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy"))); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } var pub = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.FromNo == it.FromNo && p.ComId == _currentcompany.id); if (pub.Count() > 0) { Messages.AddErrorMessage(string.Format("Đã tồn tại giải hóa đơn tương ứng ký hiệu {0}", it.InvSerial)); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } } if (pubSrc.CreateNew(mPub, lst, out message) == true) { _currentcompany.IsUsed = true; _comSrv.Update(_currentcompany); _comSrv.CommitChanges(); StringBuilder InvInfo = new StringBuilder(); for (int i = 0; i < lst.Count; i++) { InvInfo.AppendFormat("{0};{1};{2};{3};{4}_", lst[i].RegisterID, lst[i].InvSerial, lst[i].Quantity, lst[i].FromNo, lst[i].ToNo); } log.Info("Create Publish by: " + HttpContext.User.Identity.Name + "|InvInfo:" + InvInfo.ToString()); Messages.AddFlashMessage("Tạo phát hành thành công!"); return(RedirectToAction("Index")); } else { log.Error("Create Publish:" + message); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } } catch (Exception ex) { JavaScriptSerializer jss = new JavaScriptSerializer(); IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList); log.Error(" CreateRPublish -" + ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } }
public ActionResult Create(Customer tmp, CustomerModel model, string[] DeliverMethod) { if (string.IsNullOrWhiteSpace(tmp.Name) || string.IsNullOrWhiteSpace(tmp.Code)) { Messages.AddErrorMessage("Cần nhập các thông tin bắt buộc."); model.tmpCustomer = tmp; return(View(model)); } IRBACMembershipProvider _MemberShipProvider = FX.Core.IoC.Resolve <IRBACMembershipProvider>(); // kiểm tra tài khoản được sử dụng chưa user us = _MemberShipProvider.GetUser(tmp.AccountName, true); if (us != null) { Messages.AddErrorMessage("Tài khoản có trong hệ thống."); model.tmpCustomer = tmp; return(View(model)); } Company _currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; ICustomerService cusSrv = IoC.Resolve <ICustomerService>(); string ErrorMessage = ""; var qr = cusSrv.Query.Where(p => p.ComID == _currentCom.id); if (!string.IsNullOrWhiteSpace(tmp.TaxCode)) { qr = qr.Where(p => p.TaxCode.ToUpper() == tmp.TaxCode.ToUpper() || p.Code.ToUpper() == tmp.Code.Trim().ToUpper()); } else { qr = qr.Where(p => p.Code.ToUpper() == tmp.Code.Trim().ToUpper()); } if (qr.Count() > 0) { model.tmpCustomer = tmp; Messages.AddErrorMessage("Mã số thuế hoặc mã khách hàng đã tồn tại trên hệ thống!"); return(View(model)); } Certificate cer = model.UpdateCertificate(new Certificate()); // user user = new user(); //add delivermethod if (DeliverMethod == null) { tmp.DeliverMethod = -1; } else if (DeliverMethod.Length == 1) { if (DeliverMethod[0] == "0") { tmp.DeliverMethod = 0; } else if (DeliverMethod[0] == "1") { tmp.DeliverMethod = 1; } } else if (DeliverMethod.Length == 2) { tmp.DeliverMethod = 2; } tmp.TaxCode = Utils.formatTaxcode(tmp.TaxCode); //end delivermethod if (cusSrv.CreateCus(tmp, cer, _currentCom.id, out ErrorMessage)) { log.Info("Create Customer by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + tmp.Name + " TaiKhoanKhachHang: " + tmp.AccountName + " Email: " + tmp.Email); Messages.AddFlashMessage(Resources.Message.Cus_IMesSuccess); // send Mail-- try { if (!string.IsNullOrEmpty(tmp.Email)) { string randompass = (_currentCom.Config.Keys.Contains("SetDefaultCusPass")) ? _currentCom.Config["SetDefaultCusPass"] : "******"; string labelEmail = _currentCom.Config.Keys.Contains("LabelMail") ? _currentCom.Config["LabelMail"] : "*****@*****.**"; string portalLink = _currentCom.Config.Keys.Contains("PortalLink") ? _currentCom.Config["PortalLink"] : "http://hddt.vinvoice.vn"; IService.IRegisterEmailService emailSrv = FX.Core.IoC.Resolve <IService.IRegisterEmailService>(); Dictionary <string, string> subjectParams = new Dictionary <string, string>(1); subjectParams.Add("$subject", ""); Dictionary <string, string> bodyParams = new Dictionary <string, string>(3); bodyParams.Add("$company", _currentCom.Name); bodyParams.Add("$cusname", tmp.Name); bodyParams.Add("$username", tmp.AccountName); bodyParams.Add("$password", randompass); bodyParams.Add("$portalLink", portalLink); emailSrv.ProcessEmail(labelEmail, tmp.Email, "RegisterCustomer", subjectParams, bodyParams); } } catch (Exception ex) { log.Error(ex); } return(RedirectToAction("Index")); } else { model.tmpCustomer = tmp; Messages.AddErrorMessage(ErrorMessage); log.Error(" Create -:" + ErrorMessage); return(View(model)); } }
public ActionResult UpdatePublish(int id, string PubInvoiceList) { if (id <= 0) { throw new HttpRequestValidationException(); } IPublishService pubSrc = IoC.Resolve <IPublishService>(); ITaxAuthorityService taxSrv = IoC.Resolve <ITaxAuthorityService>(); Publish opub = pubSrc.Getbykey(id); try { TryUpdateModel <Publish>(opub); opub.TaxAuthorityName = (from tax in taxSrv.Query where tax.Code == opub.TaxAuthorityCode select tax.Name).FirstOrDefault(); JavaScriptSerializer jss = new JavaScriptSerializer(); IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList); foreach (var it in lst) { IPublishInvoiceService pubinvSrv = IoC.Resolve <IPublishInvoiceService>(); ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); string invSer = string.Format("{0}/{1}E", it.InvSerialPrefix, it.InvSerialSuffix); var old = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate > it.StartDate && p.FromNo < it.FromNo && p.ComId == _currentcompany.id).FirstOrDefault(); if (old != null) { Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu từ ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy"))); PublishModel model = new PublishModel(); model.mPublish = opub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>(); return(View("EditRPublish", model)); } else { old = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate <it.StartDate && p.FromNo> it.FromNo && p.ComId == _currentcompany.id).FirstOrDefault(); if (old != null) { Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu nhỏ hơn ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy"))); PublishModel model = new PublishModel(); model.mPublish = opub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>(); return(View("EditRPublish", model)); } } } string mess = ""; if (pubSrc.Update(opub, lst, out mess) == true) { StringBuilder InvInfo = new StringBuilder(); for (int i = 0; i < lst.Count; i++) { InvInfo.AppendFormat("{0};{1};{2};{3};{4}_", lst[i].RegisterID, lst[i].InvSerial, lst[i].Quantity, lst[i].FromNo, lst[i].ToNo); } log.Info("Edit Publish by: " + HttpContext.User.Identity.Name + "|InvInfo:" + InvInfo.ToString()); Messages.AddFlashMessage("Sửa thành công"); return(RedirectToAction("Index")); } else { log.Error("Update Publish:" + mess); ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); PublishModel model = new PublishModel(); model.mPublish = opub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>(); Messages.AddErrorMessage(mess); return(View("EditRPublish", model)); } } catch (Exception ex) { log.Error("EditRPublish -" + ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); PublishModel model = new PublishModel(); model.mPublish = opub; ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>(); return(View("EditRPublish", model)); } }
public ActionResult Update(int id, string RetypePassword, string[] UserRoles, string fullname) { if (id <= 0) { throw new HttpRequestValidationException(); } IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); user Ouser = _MemberShipProvider.GetUser(id, false); if (HttpContext.User.Identity.Name == Ouser.username) { Messages.AddErrorFlashMessage(Resources.Message.User_UMesCantEdit); return(RedirectToAction("index")); } //lay doi tuong tai khoan cu string OldPassword = Ouser.password; string Oldusername = Ouser.username; AccountModel model = new AccountModel(); try { TryUpdateModel <user>(Ouser); if (Ouser.password != RetypePassword) { Messages.AddErrorMessage(Resources.Message.User_MesConfirmPass); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = Ouser.password = OldPassword; model.AllRoles = lst.ToArray(); model.UserRoles = _RoleProvider.GetRolesForUser(Ouser.userid); model.UserTmp = Ouser; return(View("Edit", model)); } if (Ouser.password != OldPassword) { Ouser.PasswordSalt = GeneratorPassword.GenerateSalt(); Ouser.password = GeneratorPassword.EncodePassword(Ouser.password, Ouser.PasswordFormat, Ouser.PasswordSalt);//FormsAuthentication.HashPasswordForStoringInConfigFile(RetypePassword, "MD5"); } Ouser.FailedPasswordAttemptCount = 0; //update lai tai khoan _MemberShipProvider.UpdateUser(Ouser); model.UserRoles = UserRoles ?? new string[] { }; _RoleProvider.UpdateUsersToRoles(Ouser.userid, model.UserRoles); Messages.AddFlashMessage(Resources.Message.User_UMesSuccess); log.Info("Update Account:" + HttpContext.User.Identity.Name + ", Date: " + DateTime.Now); Company currentComp = ((EInvoiceContext)FXContext.Current).CurrentCompany; IStaffService _staSrv = IoC.Resolve <IStaffService>(); Staff sta = _staSrv.SearchByAccountName(Ouser.username, currentComp.id); sta.FullName = fullname; _staSrv.UpdateStaff(sta); return(RedirectToAction("index")); } catch (Exception ex) { log.Error("Error Update:", ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = Ouser.password = OldPassword; model.AllRoles = lst.ToArray(); model.UserRoles = _RoleProvider.GetRolesForUser(Ouser.userid); model.UserTmp = Ouser; return(View("Edit", model)); } }
public ActionResult ConfigCertify(string VAN_TAX_OFFICE_CODE, string VAN_AUT_CODE, string VAN_SYSTEM_CODE) { if (String.IsNullOrEmpty(VAN_AUT_CODE) || String.IsNullOrEmpty(VAN_SYSTEM_CODE) || String.IsNullOrEmpty(VAN_TAX_OFFICE_CODE)) { Messages.AddErrorFlashMessage("Xin lỗi, cả ba trường dữ liệu trên là bắt buộc, bạn xem lại hướng dẫn bên dưới để cập nhật chính xác!"); return(View(new { VAN_AUT_CODE = VAN_AUT_CODE, VAN_SYSTEM_CODE = VAN_SYSTEM_CODE, VAN_TAX_OFFICE_CODE = VAN_TAX_OFFICE_CODE })); } try { Company company = ((EInvoiceContext)FXContext.Current).CurrentCompany; ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); IConfigService configSrv = IoC.Resolve <IConfigService>(); var authenCode = configSrv.Query.FirstOrDefault(c => c.ComID == company.id && c.Key == "VAN_AUT_CODE"); if (authenCode != null) { authenCode.Value = VAN_AUT_CODE; } else { configSrv.CreateNew(new Config { ComID = company.id, Key = "VAN_AUT_CODE", Value = VAN_AUT_CODE }); } var taxOfficeCode = configSrv.Query.FirstOrDefault(c => c.ComID == company.id && c.Key == "VAN_TAX_OFFICE_CODE"); if (taxOfficeCode != null) { taxOfficeCode.Value = VAN_TAX_OFFICE_CODE; } else { configSrv.CreateNew(new Config { ComID = company.id, Key = "VAN_TAX_OFFICE_CODE", Value = VAN_TAX_OFFICE_CODE }); } var systemCode = configSrv.Query.FirstOrDefault(c => c.ComID == company.id && c.Key == "VAN_SYSTEM_CODE"); if (systemCode != null) { systemCode.Value = VAN_SYSTEM_CODE; } else { configSrv.CreateNew(new Config { ComID = company.id, Key = "VAN_SYSTEM_CODE", Value = VAN_SYSTEM_CODE }); } configSrv.CommitChanges(); Messages.AddFlashMessage("Cập nhật thông tin chuỗi định danh mật khẩu thành công!"); return(RedirectToAction(actionName: "Index", controllerName: "Home")); } catch (Exception ex) { log.Error(ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); } return(View(new { VAN_AUT_CODE = VAN_AUT_CODE, VAN_TAX_CODE = VAN_TAX_OFFICE_CODE })); }
public ActionResult New(user temp, string RetypePassword, string[] UserRoles, string fullname) { IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); if (string.IsNullOrWhiteSpace(temp.username)) { AccountModel model = new AccountModel(); Messages.AddErrorMessage("Cần nhập những thông tin bắt buộc."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = UserRoles ?? new string[] { }; model.UserTmp = temp; return(View("Create", model)); } try { if (temp.password != RetypePassword) { AccountModel model = new AccountModel(); Messages.AddErrorMessage(Resources.Message.User_MesConfirmPass); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = UserRoles ?? new string[] { }; model.UserTmp = temp; return(View("Create", model)); } //Tao tai khoan string status = ""; Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; user u = _MemberShipProvider.CreateUser(temp.username, temp.password, temp.email, null, null, temp.IsApproved, null, currentCom.id.ToString(), out status); if (status != "Success") { AccountModel model = new AccountModel(); Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = UserRoles ?? new string[] { }; model.UserTmp = temp; return(View("Create", model)); } _RoleProvider.UpdateUsersToRoles(u.userid, UserRoles); Messages.AddFlashMessage(Resources.Message.User_UMesSuccess); log.Info("Create Account:" + HttpContext.User.Identity.Name + ", Date: " + DateTime.Now); Company currentComp = ((EInvoiceContext)FXContext.Current).CurrentCompany; IStaffService _staSrv = IoC.Resolve <IStaffService>(); Staff newStaff = new Staff { FullName = fullname, AccountName = u.username, ComID = currentComp.id, Email = u.email }; _staSrv.CreateNew(newStaff); _staSrv.CommitChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error("Create Error:", ex); AccountModel model = new AccountModel(); Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = new string[] { }; model.UserTmp = temp; return(View("Create", model)); } }
public ActionResult Edit(int roleid, string[] permissions) { if (roleid <= 0) { throw new HttpRequestValidationException(); } IroleService _RoleSrc = IoC.Resolve <IroleService>(); IpermissionService _PermissionSrc = IoC.Resolve <IpermissionService>(); IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); role omodel = _RoleSrc.Getbykey(roleid); try { TryUpdateModel <role>(omodel); if (permissions == null || permissions.Count() == 0) { Messages.AddErrorMessage("Cần chọn permission."); RoleModel model = new RoleModel(); model.Id = roleid; model.name = omodel.name; model.Permissions = omodel.Permissions.ToList <permission>(); List <permission> lPermissions = _PermissionSrc.Query.Where(a => a.AppID == _MemberShipProvider.Application.AppID).OrderBy(p => p.Description).ToList <permission>(); ViewData["Permissions"] = lPermissions; return(View("Edit", model)); } if (omodel != null) { omodel.Permissions = _PermissionSrc.Query.Where(p => permissions.Contains(p.name)).OrderBy(p => p.Description).ToList <permission>(); _RoleSrc.Update(omodel); _RoleSrc.CommitChanges(); Messages.AddFlashMessage("Sửa role thành công."); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Role - Edit : " + omodel.roleid, "Edit Role Success : " + " Info--NameRole " + omodel.name, LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(RedirectToAction("Index")); } else { RoleModel model = new RoleModel(); model.Id = roleid; model.name = omodel.name; model.Permissions = omodel.Permissions.ToList <permission>(); List <permission> lPermissions = _PermissionSrc.Query.Where(a => a.AppID == _MemberShipProvider.Application.AppID).OrderBy(p => p.Description).ToList <permission>(); ViewData["Permissions"] = lPermissions; Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Role - Edit : " + omodel.roleid, "Edit Role Error :" + "Edit Role - role null", LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(View("Edit", model)); } } catch (Exception ex) { logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Role - Edit : " + omodel.roleid, "Edit Role Error :" + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); RoleModel model = new RoleModel(); model.Id = roleid; model.name = omodel.name; model.Permissions = omodel.Permissions.ToList <permission>(); List <permission> lPermissions = _PermissionSrc.Query.Where(a => a.AppID == _MemberShipProvider.Application.AppID).OrderBy(p => p.Description).ToList <permission>(); ViewData["Permissions"] = lPermissions; Messages.AddErrorMessage("Có lỗi trong quá trình sửa role."); return(View("Edit", model)); } }
public ActionResult Edit(Videos video) { IVideosService videoSrv = IoC.Resolve <IVideosService>(); //Videos oldVideo = videoSrv.Getbykey(video.Id); try { TryUpdateModel <Videos>(video); video.ModifiedBy = HttpContext.User.Identity.Name; video.ModifiedDate = DateTime.Now; //Kiểm trra người dùng có thực hiện đăng video mới thay thế hay không //if (video.VideoPath != oldVideo.VideoPath) //{ if (video.LinkType == LinkType.Youtube) { byte[] imgBytes; string yId; WebClient cli = new WebClient(); if (video.VideoPath.IndexOf("embed") <= 0) { string[] arr = video.VideoPath.Split('='); yId = arr[1]; string convertToEmbedLink = "https://www.youtube.com/embed/" + yId; video.VideoPath = convertToEmbedLink; imgBytes = cli.DownloadData("http://img.youtube.com/vi/" + yId + "/0.jpg"); } else { string[] arr = video.VideoPath.Split('/'); yId = arr[arr.Length - 1]; } imgBytes = cli.DownloadData("http://img.youtube.com/vi/" + yId + "/0.jpg"); System.IO.File.WriteAllBytes(ConfigurationSettings.AppSettings.Get("PhysicalSiteDataDirectory") + @"\_thumbs\Videos\" + yId + ".jpg", imgBytes); video.ImagePath = "/UploadStore/Videos/" + yId + ".jpg"; } else { //Sửa video tự tự upload thì tiến hành convert video vừa sửa sang mp4 hoặc webm ConvertVideo conv = new ConvertVideo(video.VideoPath); if (video.VideoPath.IndexOf("mp4") > 0) { Thread thread = new Thread(new ThreadStart(conv.ConvertVideoToWebM)); thread.Start(); } else if (video.VideoPath.IndexOf("webm") > 0) { Thread thread = new Thread(new ThreadStart(conv.ConvertVideoToMp4)); thread.Start(); } string videoFull = video.VideoPath.Split('/')[3]; string videoName = videoFull.Split('.')[0]; string imageName = "/UploadStore/Videos/" + videoName + ".jpg"; video.ImagePath = imageName; } // } // video.URLName = FX.Utils.Common.TextHelper.ToUrlFriendly(video.NameVNI); videoSrv.Update(video); videoSrv.CommitChanges(); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Edit : " + video.Id, "Edit Video Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); Messages.AddFlashMessage("Cập nhật thành công."); return(RedirectToAction("Index")); } catch (Exception ex) { logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Edit : " + video.Id, "Edit Video Error " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); IVideoTypeService videoCateSrv = IoC.Resolve <IVideoTypeService>(); VideoModels model = new VideoModels(); model.Video = video; model.VideoTypes = videoCateSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList(); return(View("Edit", model)); } }