예제 #1
0
        public ViewModel.ReturnResult <bool> AddProjectCategory(ViewModel.ProjectCategoryModel projectCategory)
        {
            var returnResult = new ViewModel.ReturnResult <bool>();

            try
            {
                var context             = new DomainDeriven.AkoSatrapDb();
                var enDbProjectCategory = new DomainDeriven.ProjectCategory();
                var dbProjectCategory   = new DomainDeriven.ProjectCategory();

                enDbProjectCategory.Title     = projectCategory.EnTitle;
                enDbProjectCategory.IsEnglish = true;

                dbProjectCategory.Title            = projectCategory.Title;
                dbProjectCategory.IsEnglish        = false;
                dbProjectCategory.ProjectCategory2 = enDbProjectCategory;
                context.ProjectCategories.Add(dbProjectCategory);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                returnResult.SetError(ex.Message);
            }

            return(returnResult);
        }
예제 #2
0
        public ViewModel.ReturnResult <bool> UpdateProjectFeature(ViewModel.ProjectFeatureModel projectFeature)
        {
            var returnResult = new ViewModel.ReturnResult <bool>();

            try
            {
                var context = new DomainDeriven.AkoSatrapDb();

                var dbProjectFeature = context.ProjectFeatures.Include("ProjectFeature2")
                                       .FirstOrDefault(r => !r.IsEnglish.Value && r.Id == projectFeature.Id);

                if (dbProjectFeature != null)
                {
                    dbProjectFeature.Title = projectFeature.Title;
                    dbProjectFeature.ProjectFeature2.Title       = projectFeature.EnTitle;
                    dbProjectFeature.Description                 = projectFeature.Description;
                    dbProjectFeature.ProjectFeature2.Description = projectFeature.EnDescription;
                    dbProjectFeature.Order = projectFeature.Order;
                    dbProjectFeature.ProjectFeature2.Order = projectFeature.Order;
                    context.SaveChanges();
                }
                else
                {
                    returnResult.SetError("جزییات محصول مورد نظر پیدا نشد");
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                returnResult.SetError(ex.Message);
            }

            return(returnResult);
        }
예제 #3
0
        public ViewModel.ProjectModel GetProjectById(int id)
        {
            var context          = new DomainDeriven.AkoSatrapDb();
            var project          = context.Projects.FirstOrDefault(r => r.Id == id);
            var projectViewModel = new ViewModel.ProjectModel
            {
                Id = project.Id,
                ProjectCategoryId = project.ProjectCategoryId.Value,
                Description       = project.Description,
                ImageFolderName   = project.ImageFolderName,
                City = project.City,
                CompletionPercentage = project.CompletionPercentage,
                CreateDate           = project.CreateDate,
                EndDate         = ConvertGregorianToPersianDate(project.EndDate),
                Province        = project.Province,
                Title           = project.Title,
                StartDate       = ConvertGregorianToPersianDate(project.StartDate),
                ProjectCategory = new ViewModel.ProjectCategoryModel
                {
                    Title = project.ProjectCategory.Title,
                    Id    = project.Id
                },
                ProjectFeatures = project.ProjectFeatures.Select(x => new ViewModel.ProjectFeatureModel
                {
                    Id          = x.Id,
                    Description = x.Description,
                    Title       = x.Title
                }).ToList()
            };

            return(projectViewModel);
        }
예제 #4
0
        public List <ViewModel.ProductModel> GetAllProduct(bool isEnglish)
        {
            DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb();

            var products = context.Products.Include("ProductCategory").Where(r => r.IsEnglish == isEnglish)
                           .Select(r => new ViewModel.ProductModel
            {
                Category = new ViewModel.ProductCategotyModel
                {
                    Title   = r.ProductCategory.Title,
                    Id      = r.ProductCategory.Id,
                    EnId    = r.Product2.ProductCategoryId.Value,
                    EnTitle = r.Product2.ProductCategory.Title
                },

                Brand           = r.Brand,
                Id              = r.Id,
                Title           = r.Title,
                ImportantTip1   = r.ImportantTip1,
                ImportantTip2   = r.ImportantTip2,
                ImportantTip3   = r.ImportantTip3,
                ImageFolderName = r.ImageFolderName,
                CategoryId      = r.ProductCategoryId.Value,
                Description     = r.Description
            }).ToList();

            return(products);
        }
예제 #5
0
        public ViewModel.ReturnResult <bool> UpdateProjectCategory(ViewModel.ProjectCategoryModel model)
        {
            var returnResult = new ViewModel.ReturnResult <bool>();

            try
            {
                var context = new DomainDeriven.AkoSatrapDb();

                var dbProjectCategory = context.ProjectCategories.Include("ProjectCategory2").FirstOrDefault(r => r.IsEnglish == false && r.Id == model.Id);
                if (dbProjectCategory != null)
                {
                    dbProjectCategory.Title = model.Title;
                    dbProjectCategory.ProjectCategory2.Title = model.EnTitle;
                    context.SaveChanges();
                }
                else
                {
                    returnResult.SetError("دسته بندی مورد نظر پیدا نشد");
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                returnResult.SetError(ex.Message);
            }
            return(returnResult);
        }
예제 #6
0
 public ViewModel.ProductCategotyModel GetProductCategory(int id)
 {
     DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb();
     return(context.ProductCategories.Include("ProductCategory2").Where(r => r.Id == id)
            .Select(r => new ViewModel.ProductCategotyModel {
         Title = r.Title, EnTitle = r.ProductCategory2.Title, Id = r.Id, EnId = r.EnId.Value
     }).FirstOrDefault());
 }
예제 #7
0
        public List <ViewModel.ProjectCategoryModel> GetAllProjectCategory()
        {
            DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb();
            var result = context.ProjectCategories.Include("ProjectCategory2").Where(r => r.IsEnglish == false)
                         .Select(r => new ViewModel.ProjectCategoryModel {
                Title = r.Title, EnTitle = r.ProjectCategory2.Title, Id = r.Id, EnId = r.EnId.Value
            }).ToList();

            return(result);
        }
예제 #8
0
        public ViewModel.ReturnResult <bool> AddProjectDetail(ViewModel.ProjectFeatureModel projectFeature)
        {
            var returnResult = new ViewModel.ReturnResult <bool>();

            try
            {
                var context = new DomainDeriven.AkoSatrapDb();

                var project = context.Projects.Include("Project2").FirstOrDefault(r => r.Id == projectFeature.ProjectId);
                if (project != null)
                {
                    var enProductFeatureDb = new DomainDeriven.ProjectFeature
                    {
                        Title       = projectFeature.EnTitle,
                        Description = projectFeature.EnDescription,
                        Order       = projectFeature.Order,
                        ProjectId   = project.Project2.Id,
                        IsEnglish   = true
                    };

                    var faProjectFeatureDb = new DomainDeriven.ProjectFeature
                    {
                        Title           = projectFeature.Title,
                        Description     = projectFeature.Description,
                        Order           = projectFeature.Order,
                        ProjectFeature2 = enProductFeatureDb,
                        ProjectId       = project.Id,
                        IsEnglish       = false
                    };

                    context.ProjectFeatures.Add(faProjectFeatureDb);

                    context.SaveChanges();
                }
                else
                {
                    returnResult.SetError("محصول مورد نظر پیدا نشدُ");
                }
            }
            catch (Exception ex)
            {
                returnResult.SetError(ex.Message);
            }

            return(returnResult);
        }
예제 #9
0
        public ViewModel.ProductModel GetProductById(int id)
        {
            DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb();

            var product = context.Products.FirstOrDefault(r => r.Id == id);

            var productViewModel = new ViewModel.ProductModel
            {
                Id              = product.Id,
                Brand           = product.Brand,
                CategoryId      = product.ProductCategoryId.Value,
                Description     = product.Description,
                ImageFolderName = product.ImageFolderName
            };

            return(productViewModel);
        }
예제 #10
0
        public List <ViewModel.ProjectModel> GetAllProject(bool isEnglish)
        {
            var context = new DomainDeriven.AkoSatrapDb();

            var projects = context.Projects.Include("Project2").Include("ProjectCategory").Where(r => r.IsEnglish == isEnglish)
                           .ToList()
                           .Select(r => new ViewModel.ProjectModel
            {
                ProjectCategory = new ViewModel.ProjectCategoryModel
                {
                    Title   = r.ProjectCategory.Title,
                    Id      = r.ProjectCategory.Id,
                    EnId    = r.Project2.ProjectCategoryId.Value,
                    EnTitle = r.Project2.ProjectCategory.Title
                },
                IsEnglish         = r.IsEnglish,
                ProjectCategoryId = r.ProjectCategoryId,
                Title             = r.Title,
                StartDate         = ConvertGregorianToPersianDate(r.StartDate),
                Province          = r.Province,
                master            = r.master,
                ImageFolderName   = r.ImageFolderName,
                Id                   = r.Id,
                Description          = r.Description,
                CreateDate           = r.CreateDate,
                CompletionPercentage = r.CompletionPercentage,
                City                 = r.City,
                EndDate              = ConvertGregorianToPersianDate(r.EndDate),
                EnId                 = r.EnId,
                EnCity               = r.Project2.City,
                EnDescription        = r.Project2.Description,
                EnProvince           = r.Project2.Province,
                EnTitle              = r.Project2.Title,
            }).ToList();

            projects.ForEach(item =>
            {
                var path = System.Web.Hosting.HostingEnvironment.MapPath($"~/AkoSatrapImages/{item.ImageFolderName}/");
                if (Directory.Exists(path))
                {
                    item.Images = Directory.GetFiles(path).Select(r => Path.GetFileName(r)).ToList();
                }
            });
            return(projects);
        }
예제 #11
0
        public ViewModel.ReturnResult <bool> AddProduct(ViewModel.ProductModel product)
        {
            ViewModel.ReturnResult <bool> returnResult = new ViewModel.ReturnResult <bool>();

            try
            {
                DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb();
                var enDbProduct = new DomainDeriven.Product();
                var dbProduct   = new DomainDeriven.Product();

                enDbProduct.Brand             = product.EnBrand;
                enDbProduct.CreateDate        = DateTime.Now;
                enDbProduct.ImageFolderName   = Guid.NewGuid().ToString();
                enDbProduct.ImportantTip1     = product.EnImportantTip1;
                enDbProduct.ImportantTip2     = product.EnImportantTip2;
                enDbProduct.ImportantTip3     = product.EnImportantTip3;
                enDbProduct.IsEnglish         = true;
                enDbProduct.ProductCategoryId = product.Category.EnId;
                enDbProduct.Title             = product.EnTitle;
                enDbProduct.Description       = product.EnDescription;


                dbProduct.Brand             = product.Brand;
                dbProduct.CreateDate        = DateTime.Now;
                dbProduct.ImageFolderName   = enDbProduct.ImageFolderName;
                dbProduct.ImportantTip1     = product.ImportantTip1;
                dbProduct.ImportantTip2     = product.ImportantTip2;
                dbProduct.ImportantTip3     = product.ImportantTip3;
                dbProduct.IsEnglish         = false;
                dbProduct.ProductCategoryId = product.Category.Id;
                dbProduct.Title             = product.Title;
                dbProduct.Description       = product.Description;
                dbProduct.Product2          = enDbProduct;

                context.Products.Add(dbProduct);

                context.SaveChanges();
            }
            catch (Exception ex)
            {
                returnResult.SetError(ex.Message);
            }

            return(returnResult);
        }
예제 #12
0
        public ViewModel.ReturnResult <bool> AddProject(ViewModel.ProjectModel project)
        {
            ViewModel.ReturnResult <bool> returnResult = new ViewModel.ReturnResult <bool>();

            try
            {
                DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb();
                var enDbProject = new DomainDeriven.Project();
                var dbProject   = new DomainDeriven.Project();

                enDbProject.Title                = project.EnTitle;
                enDbProject.Description          = project.EnDescription;
                enDbProject.Province             = project.EnProvince;
                enDbProject.City                 = project.EnCity;
                enDbProject.CreateDate           = DateTime.Now;
                enDbProject.StartDate            = ConvertPersianDateToGregorian(project.StartDate);
                enDbProject.EndDate              = ConvertPersianDateToGregorian(project.EndDate);
                enDbProject.CompletionPercentage = project.CompletionPercentage;
                enDbProject.ProjectCategoryId    = project.ProjectCategory != null ? project.ProjectCategory.EnId : 0;
                enDbProject.IsEnglish            = true;
                enDbProject.ImageFolderName      = Guid.NewGuid().ToString();

                dbProject.Title                = project.Title;
                dbProject.Description          = project.Description;
                dbProject.Province             = project.Province;
                dbProject.City                 = project.City;
                dbProject.CreateDate           = DateTime.Now;
                dbProject.StartDate            = ConvertPersianDateToGregorian(project.StartDate);
                dbProject.EndDate              = ConvertPersianDateToGregorian(project.EndDate);
                dbProject.CompletionPercentage = project.CompletionPercentage;
                dbProject.ProjectCategoryId    = project.ProjectCategory != null ? project.ProjectCategory.Id : 0;
                dbProject.IsEnglish            = false;
                dbProject.ImageFolderName      = Guid.NewGuid().ToString();
                dbProject.Project2             = enDbProject;

                context.Projects.Add(dbProject);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                returnResult.SetError(ex.Message);
            }

            return(returnResult);
        }
예제 #13
0
        public List <ViewModel.ProjectFeatureModel> GetAllProjectDetail(int projectId)
        {
            var context            = new DomainDeriven.AkoSatrapDb();
            var projectFeatureList = context.ProjectFeatures.Include("ProjectFeatures2").Where(r => !r.IsEnglish.Value && r.ProjectId == projectId)
                                     .Select(r => new ViewModel.ProjectFeatureModel
            {
                Title         = r.Title,
                EnTitle       = r.ProjectFeature2.Title,
                Id            = r.Id,
                EnId          = r.EnId.Value,
                Description   = r.Description,
                EnDescription = r.ProjectFeature2.Description,
                Order         = r.Order.Value,
                ProjectId     = r.ProjectId.Value
            }).ToList();

            return(projectFeatureList);
        }
예제 #14
0
        public List <ViewModel.ProductModel> GetAllProduct()
        {
            DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb();

            var products = context.Products.Include("Product2").Include("ProductCategory").Where(r => r.IsEnglish == false)
                           .Select(r => new ViewModel.ProductModel
            {
                Category = new ViewModel.ProductCategotyModel
                {
                    Title   = r.ProductCategory.Title,
                    Id      = r.ProductCategory.Id,
                    EnId    = r.Product2.ProductCategoryId.Value,
                    EnTitle = r.Product2.ProductCategory.Title
                },

                Brand           = r.Brand,
                Id              = r.Id,
                Title           = r.Title,
                ImportantTip1   = r.ImportantTip1,
                ImportantTip2   = r.ImportantTip2,
                ImportantTip3   = r.ImportantTip3,
                ImageFolderName = r.ImageFolderName,
                CategoryId      = r.ProductCategoryId.Value,
                Description     = r.Description,
                EnBrand         = r.Product2.Brand,
                EnId            = r.Product2.Id,
                EnImportantTip1 = r.Product2.ImportantTip1,
                EnImportantTip2 = r.Product2.ImportantTip2,
                EnImportantTip3 = r.Product2.ImportantTip3,
                EnTitle         = r.Product2.Title,
                EnDescription   = r.Product2.Description,
            }).ToList();

            products.ForEach(item =>
            {
                var path = System.Web.Hosting.HostingEnvironment.MapPath($"~/AkoSatrapImages/{item.ImageFolderName}/");
                if (Directory.Exists(path))
                {
                    item.Images = Directory.GetFiles(path).Select(r => Path.GetFileName(r)).ToList();
                }
            });

            return(products);
        }
예제 #15
0
        public ViewModel.ReturnResult <bool> UpdateProject(ViewModel.ProjectModel project)
        {
            var returnResult = new ViewModel.ReturnResult <bool>();

            try
            {
                var context = new DomainDeriven.AkoSatrapDb();

                var dbProjectCategory = context.Projects.Include("Project2").FirstOrDefault(r => r.IsEnglish == false && r.Id == project.Id);
                if (dbProjectCategory != null)
                {
                    dbProjectCategory.Title                = project.Title;
                    dbProjectCategory.Description          = project.Description;
                    dbProjectCategory.CompletionPercentage = project.CompletionPercentage;
                    dbProjectCategory.ProjectCategoryId    = project.ProjectCategory.Id;
                    dbProjectCategory.City      = project.City;
                    dbProjectCategory.Province  = project.Province;
                    dbProjectCategory.StartDate = ConvertPersianDateToGregorian(project.StartDate);
                    dbProjectCategory.EndDate   = ConvertPersianDateToGregorian(project.EndDate);

                    dbProjectCategory.Project2.Title                = project.EnTitle;
                    dbProjectCategory.Project2.Description          = project.EnDescription;
                    dbProjectCategory.Project2.City                 = project.EnCity;
                    dbProjectCategory.Project2.Province             = project.EnProvince;
                    dbProjectCategory.Project2.StartDate            = ConvertPersianDateToGregorian(project.StartDate);
                    dbProjectCategory.Project2.EndDate              = ConvertPersianDateToGregorian(project.EndDate);
                    dbProjectCategory.Project2.CompletionPercentage = project.CompletionPercentage;
                    dbProjectCategory.Project2.ProjectCategoryId    = project.ProjectCategory.Id;

                    context.SaveChanges();
                }
                else
                {
                    returnResult.SetError("دسته بندی مورد نظر پیدا نشد");
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                returnResult.SetError(ex.Message);
            }

            return(returnResult);
        }
예제 #16
0
        public ViewModel.ReturnResult <bool> UpdateProduct(ViewModel.ProductModel product)
        {
            ViewModel.ReturnResult <bool> returnResult = new ViewModel.ReturnResult <bool>();
            try
            {
                DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb();

                var dbProductCategory = context.Products.Include("Product2").FirstOrDefault(r => r.IsEnglish == false && r.Id == product.Id);
                if (dbProductCategory != null)
                {
                    dbProductCategory.Title         = product.Title;
                    dbProductCategory.Brand         = product.Brand;
                    dbProductCategory.ImportantTip1 = product.ImportantTip1;
                    dbProductCategory.ImportantTip2 = product.ImportantTip2;
                    dbProductCategory.ImportantTip3 = product.ImportantTip3;
                    dbProductCategory.Description   = product.Description;

                    dbProductCategory.Product2.Title         = product.EnTitle;
                    dbProductCategory.Product2.Brand         = product.EnBrand;
                    dbProductCategory.Product2.ImportantTip1 = product.EnImportantTip1;
                    dbProductCategory.Product2.ImportantTip2 = product.EnImportantTip2;
                    dbProductCategory.Product2.ImportantTip3 = product.EnImportantTip3;
                    dbProductCategory.Product2.Description   = product.EnDescription;

                    context.SaveChanges();
                }
                else
                {
                    returnResult.SetError("دسته بندی مورد نظر پیدا نشد");
                }


                context.SaveChanges();
            }
            catch (Exception ex)
            {
                returnResult.SetError(ex.Message);
            }

            return(returnResult);
        }
예제 #17
0
        public ViewModel.ProductModel GetProduct(int id)
        {
            DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb();
            var productView = new ViewModel.ProductModel();
            var product     = context.Products.Include("ProductCategory").Include("ProductFeatures").FirstOrDefault(r => r.Id == id);

            if (product != null)
            {
                productView = new ViewModel.ProductModel
                {
                    Category = new ViewModel.ProductCategotyModel
                    {
                        Title   = product.ProductCategory.Title,
                        Id      = product.ProductCategory.Id,
                        EnId    = product.Product2.ProductCategoryId.Value,
                        EnTitle = product.Product2.ProductCategory.Title
                    },

                    Brand           = product.Brand,
                    Id              = product.Id,
                    Title           = product.Title,
                    ImportantTip1   = product.ImportantTip1,
                    ImportantTip2   = product.ImportantTip2,
                    ImportantTip3   = product.ImportantTip3,
                    ImageFolderName = product.ImageFolderName,
                    CategoryId      = product.ProductCategoryId.Value,
                    Description     = product.Description
                };
                productView.ProductFeature = new List <ViewModel.ProductFeatureModel>();
                product.ProductFeatures.ToList().ForEach(feature => {
                    productView.ProductFeature.Add(new ViewModel.ProductFeatureModel {
                        Title = feature.Title, Id = feature.Id, Description = feature.Description
                    });
                });
            }

            return(productView);
        }