public ActionResult Load(string ImageOrFile, long tableId, long productId, int typeOfFileOrImage) { //typeOfFileOrImage = 1 yani axe asli mahsool //typeOfFileOrImage = 2 yani axaye digeye mahsool using (DatisEntities de = new DatisEntities()) { if (ImageOrFile == "1")//yani image mikhad load beshe { var result = de.Images.Where(m => m.TableId == tableId && m.ProductId == productId && m.Type == typeOfFileOrImage).Select(x => new { adress = x.Path, id = x.Id }).ToList(); return(Json(result, JsonRequestBehavior.AllowGet)); } else//yani file mikhad load beshe { var result = de.Files.Where(m => m.TableId == tableId && m.ForeignId == productId && m.Type == typeOfFileOrImage).Select(x => new FilesVM { adress = x.Path, id = x.Id, typeOfFile = x.Extension, name = x.Name }).ToList(); foreach (var item in result) { if (item.typeOfFile == ".zip") { item.adress = "Images/zip-icon.png"; } else if (item.typeOfFile == ".pdf") { item.adress = "Images/pdf-icon.png"; } else { item.adress = "Images/file-icon.png"; } } return(Json(result, JsonRequestBehavior.AllowGet)); } } }
public override void AddUsersToRoles(string[] usernames, string[] roleNames) { foreach (string rolename in roleNames) { if (string.IsNullOrEmpty(rolename)) throw new ProviderException("Role name cannot be empty or null."); if (!RoleExists(rolename)) throw new ProviderException("Role name not found."); } using (var de = new DatisEntities()) { foreach (var userName in usernames) { var userId = WebSecurity.GetUserId(userName); var user = de.UserProfiles.FirstOrDefault(m => m.UserId == userId); if (user != null) { foreach (var roleName in roleNames) { var role = de.webpages_Roles.FirstOrDefault(n => n.RoleName == roleName); user.webpages_Roles.Add(role); } de.Entry(user).State = EntityState.Modified; de.SaveChanges(); } } } }
public ActionResult RemoveProjectOrder(int id, int projectId) { using (DatisEntities de = new DatisEntities()) { if (id > 0) { var user = de.UserProfiles.FirstOrDefault(m => m.UserName.Equals(User.Identity.Name)); if (user != null) { de.Orders.Remove(de.Orders.FirstOrDefault(m => m.Id == id)); de.ProjectOrders.RemoveRange(de.ProjectOrders.Where(m => m.OrderId == id && m.ProjectId == projectId)); } de.SaveChanges(); var result = new { success = true, message = "محصول مورد نظر شما با موفقیت حذف شد." }; return(Json(result, JsonRequestBehavior.AllowGet)); } var result2 = new { success = false, message = "خطا در حذف" }; return(Json(result2, JsonRequestBehavior.AllowGet)); } }
public override bool RoleExists(string roleName) { using (var de = new DatisEntities()) { return de.webpages_Roles.Any(m => m.RoleName == roleName); } }
public ActionResult Repair() { List <SelectListItem> tamirMarjoo = new List <SelectListItem>(); tamirMarjoo.Add(new SelectListItem() { Text = "تعمیر", Value = "0" }); tamirMarjoo.Add(new SelectListItem() { Text = "مرجوعی از فروش", Value = "1" }); using (var de = new DatisEntities()) { List <SelectListItem> states = de.States.Select(m => new SelectListItem() { Text = m.Name, Value = SqlFunctions.StringConvert((double)m.Id).Trim() }).ToList(); ViewBag.tamirmarjoo = tamirMarjoo; ViewBag.states = states; return(View()); } }
public ActionResult GetUserOrder(int take, int skip, int page, int pageSize) { using (var de = new DatisEntities()) { PersianCalendar pc = new PersianCalendar(); var userProfile = de.UserProfiles.FirstOrDefault(m => m.UserName.Equals(User.Identity.Name)); if (userProfile != null) { var userid = userProfile.UserId; var orders = de.Orders.Where(o => o.UserId == userid).OrderBy(m => m.OrderDate).Skip(skip).Take(take).ToList(); var res = new List <OrderVM>(); foreach (var item in orders) { var order = new OrderVM(); order.Tarikh = string.Format("{0}/{1}/{2}", pc.GetYear(item.OrderDate ?? DateTime.MinValue), pc.GetMonth(item.OrderDate ?? DateTime.MinValue), pc.GetDayOfMonth(item.OrderDate ?? DateTime.MinValue)); order.Id = item.Id; var product = de.Products.FirstOrDefault(p => p.Id == item.ProductId); if (product != null) { order.ProductName = product.Model; } order.Tedad = item.Tedad.ToString(); res.Add(order); } return(Json(res, JsonRequestBehavior.AllowGet)); } return(Json("", JsonRequestBehavior.AllowGet)); } }
// // GET: /BrandAdmin/ public ActionResult AjaxRead(RepairSearchVM searchOptions, StoreRequestParams parameters) { using (DatisEntities pe = new DatisEntities()) { var all = pe.Repairs.Where(x => (x.Eshkal.Contains(searchOptions.Eshkal) || searchOptions.Eshkal == null) && (x.NameSherkat.Contains(searchOptions.NameSherkat) || searchOptions.NameSherkat == null)).Select(m => new RepairVM() { Id = m.Id, TamirOrMarjoo = m.TamirOrMarjoo == 0 ? "تعمیر" : "مرجوعی از فروش", NameSherkat = m.NameSherkat, NameMasool = m.NameMasool, Ostan = pe.States.Where(b => b.Id == m.Ostan).FirstOrDefault().Name, Shahrestan = pe.Cities.Where(b => b.Id == m.Shahrestan).FirstOrDefault().Name, CodePosti = m.CodePosti, Tel = m.Tel, Mobile = m.Mobile, Email = m.Email, ModelDastgah = m.ModelDastgah, ShomareSerialDastgah = m.ShomareSerialDastgah, ShomareFactor = m.ShomareFactor, FactorDate = m.FactorDate, Address = m.Address, Eshkal = m.Eshkal }); var result = all.OrderBy(x => x.Id).ApplyPaging(parameters).ToList(); return(this.Store(result, all.Count())); } }
public ActionResult Search(string term) { using (var de = new DatisEntities()) { UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext); List <ProductVM> productsVM = new List <ProductVM>(); foreach (var product in de.Products.Where(m => m.Model.Contains(term)).Take(6)) { Image mLogo = de.Images.Where(m => m.ProductId == product.Id && m.Type == (int)DatisEnums.ImgeType.Main && m.TableId == (int)DatisEnums.TableId.Product).FirstOrDefault(); Image bLogo = de.Images.Where(m => m.BrandId == product.BrandCategory.BrandId && m.TableId == (int)DatisEnums.TableId.Brand).FirstOrDefault(); ProductVM pvm = new ProductVM() { Model = product.Model, Id = product.Id, Description = product.Description, MainImage = mLogo != null ? mLogo.Path : "", MainImage200 = mLogo != null?mLogo.Path.AddDirectoryToPath("200") : "", MainImage350 = mLogo != null?mLogo.Path.AddDirectoryToPath("350") : "", MainImage60 = mLogo != null?mLogo.Path.AddDirectoryToPath("60") : "", BrandName = product.BrandCategory.Brand.Name, BrandLogo = bLogo != null?bLogo.Path.AddDirectoryToPath("60") : "", Link = u.Action("Detail", "Product", new { Id = product.Id, ProductTitle = product.Model }) }; productsVM.Add(pvm); } return(Json(productsVM, JsonRequestBehavior.AllowGet)); } }
public ActionResult Delete(long Id, int FileOrImage) { using (var de = new DatisEntities()) { if (FileOrImage == 1) { var image = de.Images.Where(m => m.Id == Id).FirstOrDefault(); string fullPath = Request.MapPath("~/" + image.Path); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } de.Images.Remove(image); de.SaveChanges(); return(Json(Id, JsonRequestBehavior.AllowGet)); } else { var file = de.Files.Where(m => m.Id == Id).FirstOrDefault(); string fullPath = Request.MapPath("~/" + file.Path); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } de.Files.Remove(file); de.SaveChanges(); return(Json(Id, JsonRequestBehavior.AllowGet)); } } }
public ActionResult AjaxRead(string serialNumber, StoreRequestParams parameters) { using (DatisEntities pe = new DatisEntities()) { var all = pe.SerialNumbers.Where(x => (x.SerialNumber1.Contains(serialNumber) || serialNumber == null)).Select(m => new SerialNumberVM() { Id = m.Id, SerialNumber = m.SerialNumber1, Name = m.Name, BuyDate = m.BuyDate, Description = m.Description, Email = m.Email, InsertDate1 = m.InsertDate ?? DateTime.MinValue, LastName = m.LastName, Mobile = m.Mobile, Product = pe.Products.Where(p => p.Id == m.ProductId).Select(n => n.Model + n.BrandCategory.Category.Name + n.BrandCategory.Brand.Name).FirstOrDefault() }); var result = all.OrderBy(x => x.Id).ApplyPaging(parameters).ToList(); foreach (var res in result) { DateTime d = DateTime.Parse(res.InsertDate1.ToString()); PersianCalendar pc = new PersianCalendar(); res.InsertDate = string.Format("{0}/{1}/{2}", pc.GetYear(d), pc.GetMonth(d), pc.GetDayOfMonth(d)); } return(this.Store(result, all.Count())); } }
public ActionResult Save(ClientsMessage model) { using (DatisEntities de = new DatisEntities()) { if (!ModelState.IsValid) { var result = new { success = false, message = Utils.GetModelStateErrorList(ModelState) }; return(Json(result, JsonRequestBehavior.AllowGet)); } else { de.ClientsMessages.Add(model); de.SaveChanges(); var result = new { success = true, message = "پیام شما با موفقیت ارسال شد. با تشکر" }; return(Json(result, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Index(ProjectMetadata project) { if (!ModelState.IsValid) { CreateOstanSelectListData(); ViewBag.Error = "لطفا فرم را به صورت صحیح پر کنید."; return(View()); } else if (Session["CaptchaRegProject"] == null || Session["CaptchaRegProject"].ToString() != project.Captcha) { ModelState.AddModelError("Captcha", "مجموع اشتباه است"); CreateOstanSelectListData(); ViewBag.Error = "عبارت امنیتی اشتباه است."; return(View()); } else { using (var de = new DatisEntities()) { Session["CaptchaRegProject"] = ""; de.Projects.Add(new Project() { NameSherkatForushgah = project.NameSherkatForushgah, NameModiramelMasool = project.NameModiramelMasool, Email = project.Email, Ostan = project.Ostan, Shahrestan = project.Shahrestan, Address = project.Address, Mobile = project.Mobile, Tel = project.Tel, TarikheSabteProject = project.TarikheSabteProject, TarikheTakhmineEjra = project.TarikheTakhmineEjra, ProjectName = project.ProjectName, OstaneProject = project.OstaneProject, ShahreProject = project.ShahreProject, AddressProject = project.AddressProject, MohandesiGhablAzForush = project.MohandesiGhablAzForush, Ejra = project.Ejra, NaghsheKeshi = project.NaghsheKeshi, MoshavereProject = project.MoshavereProject, Janamayi = project.Janamayi, Nezarat = project.Nezarat }); de.SaveChanges(); ModelState.Clear(); ViewBag.Success = "با تشکر،درخواست شما با موفقیت ارسال شد."; CreateOstanSelectListData(); var pr = new Project(); de.Projects.Add(pr); de.SaveChanges(); var meta = new ProjectMetadata() { Id = pr.Id }; return(View(meta)); } } }
public ActionResult Save(int fromCategoryId, int toCategoryId, Boolean DeleteFeatures) { //var a = Request.Form[0]; if (!ModelState.IsValid) { var result = new { success = false, message = Utils.GetModelStateErrorList(ModelState) }; return(Json(result, JsonRequestBehavior.AllowGet)); } else { if (fromCategoryId == toCategoryId) { var result = new { success = true, message = "کپی بین دسته بندی های متفاوت فقط امکان پذیر است.", data = new { Id = -1 } }; return(Json(result, JsonRequestBehavior.AllowGet)); } using (DatisEntities de = new DatisEntities()) { if (DeleteFeatures) { var toDelete = de.Features.Where(m => m.CategoryId == toCategoryId); foreach (var item in toDelete) { de.Features.Remove(item); } de.SaveChanges(); } var features = de.Features.Where(m => m.CategoryId == fromCategoryId); foreach (var item in features) { if (!de.Features.Any(m => m.CategoryId == toCategoryId && m.Name == item.Name)) { Feature f = new Feature() { CategoryId = toCategoryId, Name = item.Name }; de.Features.Add(f); } } de.SaveChanges(); var result = new { success = true, message = "ثبت اطلاعات با موفقیت انجام شد", data = new { Id = -1 } }; return(Json(result, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Read() { using (DatisEntities de = new DatisEntities()) { var all = de.SiteContents.Where(m => m.ArticleType == (int)DatisEnums.ArticleType.Projects).FirstOrDefault(); return(Json(all, JsonRequestBehavior.AllowGet)); } }
public ActionResult Index() { using (var de = new DatisEntities()) { var user = de.UserProfiles.FirstOrDefault(m => m.UserName.Equals(User.Identity.Name)); ViewBag.CustNo = user != null ? user.CustomerNo : "بدون شماره مشتری"; } return(View()); }
public ActionResult Index() { using (DatisEntities de = new DatisEntities()) { SiteContent sc = de.SiteContents.Where(m => m.ArticleType == (int)DatisEnums.ArticleType.Projects).FirstOrDefault(); return(View(sc)); } }
// // GET: /AnalogBoxAdmin/ public ActionResult AjaxRead(TermsOfGarrantySearchVM searchOptions, StoreRequestParams parameters) { var pe = new DatisEntities(); var all = pe.SiteContents.Where(x => (x.Title.Contains(searchOptions.Name) || searchOptions.Name == null) && (x.Article.Contains(searchOptions.Description) || searchOptions.Description == null) && x.ArticleType == (int)DatisEnums.ArticleType.NewsRoom); var result = all.OrderBy(x => x.Id).ApplyPaging(parameters).ToList(); return(this.Store(result, all.Count())); }
public ActionResult SideBar() { List <TopMenuVM> brands = null; using (DatisEntities de = new DatisEntities()) { brands = de.Brands.Select(m => new TopMenuVM() { BrandName = m.Name, BrandId = m.Id }).ToList(); foreach (var brandvm in brands) { var brandCats = de.BrandCategories.Where(x => x.BrandId == brandvm.BrandId).ToList(); var cats = de.BrandCategories.Where(x => x.BrandId == brandvm.BrandId).Select(m => m.Category).ToList(); var listCategory = new List <MenuCategoryVM>(); foreach (var bcat in brandCats) { if (bcat.Category.ParentId == null) { var rootCat = new MenuCategoryVM() { CatId = bcat.Id, Name = bcat.Category.Name }; List <int?> childs = new List <int?>(); childs = de.CategoryChildrens.Where(p => p.ParentId == bcat.Category.Id).Select(z => z.ChildId).ToList(); rootCat.Children = de.BrandCategories.Where(m => childs.Contains(m.CategoryId) && m.BrandId == brandvm.BrandId).Select(n => new MenuCategoryVM() { Name = n.Category.Name, CatId = n.Id }).ToList(); foreach (var item in rootCat.Children) { List <int?> childs2 = new List <int?>(); childs2 = de.CategoryChildrens.Where(p => p.ParentId == item.CatId).Select(z => z.ChildId).ToList(); item.Children = de.BrandCategories.Where(m => childs2.Contains(m.CategoryId) && m.BrandId == brandvm.BrandId).Select(n => new MenuCategoryVM() { Name = n.Category.Name, CatId = n.Id }).ToList(); } listCategory.Add(rootCat); } } brandvm.Categories = listCategory; } //brands.RemoveRange(1, brands.Count - 1); return(PartialView("_SideBar", brands.ToList())); } //return PartialView("_SideBar"); }
public ActionResult CityLookup(int stateId) { using (var de = new DatisEntities()) { var result = de.Cities.Where(n => n.StateId == stateId).Select(m => new { Id = m.Id, Title = m.Name }).ToList(); return(Json(result, JsonRequestBehavior.AllowGet)); } }
public ActionResult CategoryLookup() { using (var de = new DatisEntities()) { var result = de.Categories.Select(m => new { Id = m.Id, Title = m.Name }).ToList(); return(Json(result, JsonRequestBehavior.AllowGet)); } }
public override string[] GetRolesForUser(string username) { using (DatisEntities objContext = new DatisEntities()) { var objUser = objContext.UserProfiles.FirstOrDefault(x => x.UserName == username); if (objUser == null) { return null; } string[] ret = objUser.webpages_Roles.Select(x => x.RoleName).ToArray(); return ret; } }
private void CreateOstanSelectListData() { using (var de = new DatisEntities()) { List <SelectListItem> states = de.States.Select(m => new SelectListItem() { Text = m.Name, Value = SqlFunctions.StringConvert((double)m.Id).Trim() }).ToList(); ViewBag.states = states; } }
public ActionResult ProductLookup(string term) { using (var de = new DatisEntities()) { var allProducts = de.Products.Select(m => new SelectListItem() { Text = m.Model + " - " + m.BrandCategory.Category.Name + " - " + m.BrandCategory.Brand.Name, Value = SqlFunctions.StringConvert((double)m.Id).Trim() }); List <SelectListItem> res = allProducts.Where(n => n.Text.Contains(term)).Take(10).ToList(); return(Json(res, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetUsers(int take, int skip, int page, int pageSize) { using (var de = new DatisEntities()) { var users = de.UserProfiles.OrderBy(m => m.UserId).Skip(skip).Take(take).Select(u => new UserVM() { Id = u.UserId, UserName = u.UserName, CustomerNo = u.CustomerNo }).ToList(); return(Json(users, JsonRequestBehavior.AllowGet)); } }
public ActionResult Add(OrderMetadata order, int projectId) { using (DatisEntities de = new DatisEntities()) { if (!ModelState.IsValid) { var keys = from item in ModelState where item.Value.Errors.Any() let error = item.Value.Errors.FirstOrDefault() where error != null select new { key = item.Key, error = error.ErrorMessage }; var res2 = JsonConvert.SerializeObject(keys); var result = new { success = false, message = res2//Utils.GetModelStateErrorList(ModelState) }; return(Json(result, JsonRequestBehavior.AllowGet)); } else { var user = de.UserProfiles.FirstOrDefault(m => m.UserName.Equals(User.Identity.Name)); if (user != null) { var newOrder = new Order() { UserId = user.UserId, ProductId = order.ProductId, Tedad = order.Tedad, OrderDate = DateTime.Now }; de.Orders.Add(newOrder); de.SaveChanges(); de.ProjectOrders.Add(new ProjectOrder() { ProjectId = projectId, OrderId = newOrder.Id }); de.SaveChanges(); } var result = new { success = true, message = "سفارش شما با موفقیت ثبت شد." }; return(Json(result, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Save(SerialNumberMetadata model) { using (DatisEntities de = new DatisEntities()) { if (!ModelState.IsValid) { var result = new { success = false, message = Utils.GetModelStateErrorList(ModelState) }; return(Json(result, JsonRequestBehavior.AllowGet)); } else if (Session["CaptchaSerialNumber"] == null || Session["CaptchaSerialNumber"].ToString() != model.Captcha) { ModelState.AddModelError("Captcha", "مجموع اشتباه است"); var result = new { success = false, message = Utils.GetModelStateErrorList(ModelState) }; return(Json(result, JsonRequestBehavior.AllowGet)); } else { Session["CaptchaSerialNumber"] = ""; de.SerialNumbers.Add(new SerialNumber() { BuyDate = model.BuyDate, Description = model.Description, Email = model.Email, InsertDate = DateTime.Now, LastName = model.LastName, Mobile = model.Mobile, Name = model.Name, ProductId = model.Product, SerialNumber1 = model.Serial, }); de.SaveChanges(); var result = new { success = true, message = string.Format("شماره سریال {0} با موفقیت ثبت شد.", model.Serial), savedSerial = model }; return(Json(result, JsonRequestBehavior.AllowGet)); } } }
public ActionResult TermsOfGarranty() { using (DatisEntities de = new DatisEntities()) { var res = de.TermsOfGarranties.Select(m => new TermsOfGarrantyVM() { Id = m.Id, Name = m.Name, Description = m.Description, Details = m.Details }).ToList(); return(View(res)); } }
public FileResult Load(string ResumeId) { if (ResumeId != null) { using (DatisEntities de = new DatisEntities()) { int resId = Convert.ToInt32(ResumeId); var result = de.Careers.Where(m => m.Id == resId).FirstOrDefault().ResumeFilePath; byte[] fileBytes = System.IO.File.ReadAllBytes(Path.Combine(Server.MapPath("~"), result)); string fileName = "resume.pdf"; return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); } } return(null); }
public ActionResult Delete(int Id) { using (DatisEntities de = new DatisEntities()) { var record = de.ClientsMessages.FirstOrDefault(m => m.Id == Id); de.ClientsMessages.Remove(record); de.SaveChanges(); var result = new { success = true, message = "حذف اطلاعات با موفقیت انجام شد" }; return(Json(result, JsonRequestBehavior.AllowGet)); } }
// // GET: /BrandAdmin/ public ActionResult AjaxRead(BrandSearchVM searchOptions, StoreRequestParams parameters) { using (DatisEntities pe = new DatisEntities()) { var all = pe.Brands.Where(x => (x.Name.Contains(searchOptions.Name) || searchOptions.Name == null)).Select(m => new BrandVM() { Id = m.Id, Name = m.Name, Description = m.Description }); var result = all.OrderBy(x => x.Id).ApplyPaging(parameters).ToList(); return(this.Store(result, all.Count())); } }