public ProductCategoryView Create(ProductCategoryView model, out string message)
        {
            ProductCategoryView result = new ProductCategoryView();

            message = null;
            try
            {
                var productCategory = Helper.ConvertProductCategoryViewToProductCategory(model);
                productCategory.CreatedDate  = DateTime.Now;
                productCategory.ModifiedDate = DateTime.Now;
                entities.ProductCategories.Add(productCategory);
                if (entities.SaveChanges() > 0)
                {
                    result = GetProductCategoryById(productCategory.ID, out message);
                }
                else
                {
                    message = Resources.MSG_THE_PRODUCT_CATEGORY_HAS_NOT_FOUND;
                }
            }
            catch (Exception ex)
            {
                string subject = "Error " + SiteSetting.SiteName + " at Create at ProductCategoryRepo at Model.Repository. ";
                message = StringHelper.Parameters2ErrorString(ex, model.ID);
                MailHelper.SendMail(SiteSetting.EmailAdmin, subject, message);
            }
            return(result);
        }
Exemple #2
0
        public static ProductCategoryView ConvertProductCategoryToProductCategoryView(v_CategoryOfProduct model)
        {
            ProductCategoryView result = new ProductCategoryView();
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <v_CategoryOfProduct, ProductCategoryView>()
                .ForMember(v => v.ID, co => co.MapFrom(src => src.ID))
                .ForMember(v => v.CatalogueId, co => co.MapFrom(src => src.CatalogueId))
                .ForMember(v => v.CatalogueName, co => co.MapFrom(src => src.CategoryName))
                .ForMember(v => v.ParentID, co => co.MapFrom(src => src.ParentId))
                .ForMember(v => v.ParentName, co => co.MapFrom(src => src.ParentName))
                .ForMember(v => v.MetaTitle, co => co.MapFrom(src => src.MetaTitle))
                .ForMember(v => v.Name, co => co.MapFrom(src => src.CategoryName))
                .ForMember(v => v.DisplayOrder, co => co.MapFrom(src => src.Orders))
                .ForMember(v => v.SeoTitle, co => co.MapFrom(src => src.Title))
                .ForMember(v => v.CreatedDate, co => co.MapFrom(src => src.CreatedDate))
                .ForMember(v => v.CreatedBy, co => co.MapFrom(src => src.CreatedBy))
                .ForMember(v => v.ModifiedDate, co => co.MapFrom(src => src.ModifiedDate))
                .ForMember(v => v.ModifiedBy, co => co.MapFrom(src => src.ModifiedBy))
                .ForMember(v => v.MetaKeywords, co => co.MapFrom(src => src.MetaKeywords))
                .ForMember(v => v.MetaDescriptions, co => co.MapFrom(src => src.MetaDescriptions))
                .ForMember(v => v.Status, co => co.MapFrom(src => src.Status))
                .ForMember(v => v.ShowOnHome, co => co.MapFrom(src => src.ShowOnHome))

                ;
            });
            IMapper mapper = config.CreateMapper();

            result = mapper.Map <v_CategoryOfProduct, ProductCategoryView>(model);
            return(result);
        }
        public ProductCategoryView GetProductCategoryById(long Id, out string message)
        {
            ProductCategoryView result = new ProductCategoryView();

            message = null;
            try
            {
                if (Id > 0)
                {
                    var categoryOfProduct = entities.v_CategoryOfProduct.FirstOrDefault(w => w.ID == Id);
                    result = Helper.ConvertProductCategoryToProductCategoryView(categoryOfProduct);
                }
                else
                {
                    message = Resources.MSG_THE_PRODUCT_CATEGORY_HAS_NOT_FOUND;
                }
            }
            catch (Exception ex)
            {
                string subject = "Error " + SiteSetting.SiteName + " at GetProductCategoryById at ProductCategoryRepo at Model.Repository";
                message = StringHelper.Parameters2ErrorString(ex, conn);
                MailHelper.SendMail(SiteSetting.EmailAdmin, subject, message);
            }
            return(result);
        }
        public async Task <IActionResult> Edit(int id, ProductCategoryView productCategoryView)
        {
            var productCategory = _context.ProductCategorys.Find(id);

            if (productCategory == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    productCategory.Map(productCategoryView);
                    _context.Update(productCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductCategoryExists(productCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(productCategory));
        }
Exemple #5
0
        public ActionResult ProductCategoryCreate(ProductCategoryView model, string saveclose, string savenew)
        {
            var actionStatus = new ActionResultHelper();

            actionStatus.ActionStatus = ResultSubmit.failed;
            string message = "";
            bool   IsValid = true;

            if (ModelState.IsValid)
            {
                model.Language   = currentCulture.ToString();
                model.CreatedBy  = CurrentUser.UserID;
                model.ModifiedBy = CurrentUser.UserID;

                ProductCategoryView remodel = _proCatRepo.Create(model, out message);

                if (remodel != null && String.IsNullOrEmpty(message))
                {
                    actionStatus.ActionStatus = ResultSubmit.success;
                    actionStatus.ErrorReason  = String.Format(SiteResource.HTML_ALERT_SUCCESS, Resources.MSG_THE_CATEGORY_HAS_CREATED_SUCCESSFULLY);
                    Session["ACTION_STATUS"]  = actionStatus;

                    if (!String.IsNullOrEmpty(saveclose))
                    {
                        return(RedirectToAction("ProductCategory"));
                    }
                    else if (!String.IsNullOrWhiteSpace(savenew))
                    {
                        return(RedirectToAction("ProductCategoryCreate"));
                    }
                    else
                    {
                        return(RedirectToAction("ProductCategoryEdit", new { Id = remodel.ID }));
                    }
                }
                else
                {
                    actionStatus.ErrorReason = String.Format(SiteResource.HTML_ALERT_ERROR, Resources.MSG_THE_CATEGORY_HAS_CREATED_UNSUCCESSFULLY);
                    Session["ACTION_STATUS"] = actionStatus;
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                IsValid = false;
                goto actionError;
            }

actionError:
            if (!IsValid)
            {
                actionStatus.ErrorReason = String.Format(SiteResource.HTML_ALERT_ERROR, Resources.MSG_ERROR_ENTER_DATA_FOR_FORM + actionStatus.ShowErrorStrings());
                Session["ACTION_STATUS"] = actionStatus;
            }

            ViewBag.Title  = Resources.CATEGORY_CREATE_A_NEW;
            ViewBag.Action = "CategoryCreate";
            return(View("ProductCategoryEdit", model));
        }
Exemple #6
0
        public ActionResult Edit(ProductCategoryView model, string saveclose, string savenew)
        {
            var actionStatus = new ActionResultHelper();

            actionStatus.ActionStatus = ResultSubmit.failed;
            string message = String.Empty;
            bool   IsValid = true;

            // TODO: Add update logic here
            if (ModelState.IsValid)
            {
                model.Language    = currentCulture.ToString();
                model.ModifiedBy  = CurrentUser.UserID;
                model.CatalogueId = SiteConfiguration.CatalogueId;
                var result = _proCatRepo.Edit(model, out message);
                var dao    = new ProductCategoryDao();
                Mapper.Initialize(cfg => cfg.CreateMap <ProductCategoryView, ProductCategory>());
                var data = Mapper.Map <ProductCategoryView, ProductCategory>(model);
                if (result != null && String.IsNullOrEmpty(message))
                {
                    actionStatus.ActionStatus            = ResultSubmit.success;
                    actionStatus.Message                 = String.Format(SiteResource.HTML_ALERT_SUCCESS, Resources.MSG_THE_PRODUCT_CATEGORY_HAS_UPDATED_SUCCESSFULLLY);
                    Session[SessionName.ActionStatusLog] = actionStatus;
                    if (!String.IsNullOrEmpty(saveclose))
                    {
                        return(RedirectToAction("Index"));
                    }
                    else if (!String.IsNullOrWhiteSpace(savenew))
                    {
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        return(RedirectToAction("Edit", new { Id = model.ID }));
                    }
                }
                else
                {
                    actionStatus.ErrorReason             = String.Format(SiteResource.HTML_ALERT_ERROR, Resources.MSG_THE_PRODUCT_CATEGORY_HAS_UPDATED_UNSUCCESSFULLLY);
                    Session[SessionName.ActionStatusLog] = actionStatus;
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                IsValid = false;
                goto actionError;
            }

actionError:
            if (!IsValid)
            {
                actionStatus.ErrorReason             = String.Format(SiteResource.HTML_ALERT_ERROR, Resources.MSG_ERROR_ENTER_DATA_FOR_FORM + actionStatus.ShowErrorStrings());
                Session[SessionName.ActionStatusLog] = actionStatus;
            }

            return(View(model));
        }
Exemple #7
0
        public static void SaveMap(this ProductCategory destination, ProductCategoryView source)
        {
            var now = DateTime.UtcNow;

            destination.Name       = source.Name;
            destination.ModifiedAt = now;
            destination.CreatedAt  = now;
            destination.Active     = source.Active;
        }
Exemple #8
0
        public ActionResult AddProduct(ProductCategoryView pcv, HttpPostedFileBase upload)
        {
            string path = Path.Combine(Server.MapPath("~/UPloads"), upload.FileName);

            upload.SaveAs(path); //file has been saved in server but not in db
            pcv.Product.Image = upload.FileName;
            db.product.Add(pcv.Product);
            db.SaveChanges();
            return(RedirectToAction("ListProducts"));
        }
Exemple #9
0
        public ActionResult ProductCategoryCreate()
        {
            var model = new ProductCategoryView();

            model.CreatedByName  = CurrentUser.Name;
            model.CreatedDate    = DateTime.Now;
            model.ModifiedByName = CurrentUser.Name;
            model.ModifiedDate   = DateTime.Now;
            return(View("ProductCategoryEdit", model));
        }
Exemple #10
0
        public ActionResult AddProduct()
        {
            var Category = db.category.ToList();

            ProductCategoryView pcv = new ProductCategoryView
            {
                category = Category
            };

            return(View(pcv));
        }
Exemple #11
0
        public ActionResult Create()
        {
            var model = new ProductCategoryView();

            model.CreatedByName  = CurrentUser.Name;
            model.CreatedDate    = DateTime.Now;
            model.ModifiedByName = CurrentUser.Name;
            model.ModifiedDate   = DateTime.Now;
            model.Status         = nameof(StatusEntity.Active);
            return(View(model));
        }
Exemple #12
0
        public ActionResult EditProduct(int id)
        {
            var product             = db.product.Single(c => c.ID == id);
            var Category            = db.category.ToList();
            ProductCategoryView pcv = new ProductCategoryView
            {
                category = Category,
                Product  = product
            };

            return(View(pcv));
        }
        public ProductCategoryView Find(long id)
        {
            var result = new ProductCategoryView();

            v_CategoryOfProduct productCategory = db.v_CategoryOfProduct
                                                  .FirstOrDefault(f => f.ID == id);
            //.FirstOrDefault();



            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <v_CategoryOfProduct, ProductCategoryView>()
                .ForMember(o => o.CatalogueId, i => i.MapFrom(src => src.CatalogueId))
                .ForMember(o => o.CatalogueName, i => i.MapFrom(src => src.CatalogueName))

                .ForMember(o => o.ID, i => i.MapFrom(src => src.ID))
                .ForMember(o => o.Name, i => i.MapFrom(src => src.CategoryName))
                .ForMember(o => o.MetaTitle, i => i.MapFrom(src => src.MetaTitle))

                .ForMember(o => o.ParentID, i => i.MapFrom(src => src.ParentId))
                .ForMember(o => o.ParentName, i => i.MapFrom(src => src.ParentName))

                .ForMember(o => o.SeoTitle, i => i.MapFrom(src => src.Title))
                .ForMember(o => o.MetaKeywords, i => i.MapFrom(src => src.MetaKeywords))
                .ForMember(o => o.MetaDescriptions, i => i.MapFrom(src => src.MetaDescriptions))

                .ForMember(o => o.ShowOnHome, i => i.MapFrom(src => src.ShowOnHome))
                .ForMember(o => o.Status, i => i.MapFrom(src => src.Status))
                .ForMember(o => o.DisplayOrder, i => i.MapFrom(src => src.Orders))


                .ForMember(o => o.CreatedBy, i => i.MapFrom(src => src.CreatedBy))
                .ForMember(o => o.CreatedDate, i => i.MapFrom(src => src.CreatedDate))
                .ForMember(o => o.CreatedByName, i => i.MapFrom(src => src.CreatedByName))
                .ForMember(o => o.ModifiedBy, i => i.MapFrom(src => src.ModifiedBy))
                .ForMember(o => o.ModifiedByName, i => i.MapFrom(src => src.ModifiedByName))
                .ForMember(o => o.ModifiedDate, i => i.MapFrom(src => src.ModifiedDate))
                ;
            });

            IMapper mapper = config.CreateMapper();

            if (productCategory != null)
            {
                result = mapper.Map <v_CategoryOfProduct, ProductCategoryView>(productCategory);
            }
            else
            {
                result = null;
            }

            return(result);
        }
        public ProductCategory ProductCategoryViewToProductCategory(ProductCategoryView productCategoryView)
        {
            ProductCategory productCategory = new ProductCategory();

            productCategory.Id          = productCategoryView.Id;
            productCategory.ParentId    = productCategoryView.ParentId;
            productCategory.ApiUserId   = productCategoryView.ApiUserId;
            productCategory.Name        = productCategoryView.Name;
            productCategory.Description = productCategoryView.Description;
            productCategory.CreateDate  = productCategoryView.CreateDate;
            productCategory.UpdateDate  = productCategoryView.UpdateDate;

            return(productCategory);
        }
        public async Task <IActionResult> Create(ProductCategoryView productCategoryView)
        {
            ProductCategory productCategory = new ProductCategory();

            productCategory.Map(productCategoryView);
            if (ModelState.IsValid)
            {
                _context.Add(productCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(productCategory));
        }
        public ProductCategoryView Edit(ProductCategoryView model, out string message)
        {
            ProductCategoryView result = new ProductCategoryView();

            message = null;
            try
            {
                var productCategory = entities.ProductCategories.Find(model.ID);
                if (productCategory != null)
                {
                    productCategory.CatalogueId  = model.CatalogueId;
                    productCategory.MetaTitle    = model.MetaTitle;
                    productCategory.Name         = model.Name;
                    productCategory.ParentID     = model.ParentID;
                    productCategory.SeoTitle     = model.SeoTitle;
                    productCategory.Status       = model.Status;
                    productCategory.ShowOnHome   = model.ShowOnHome;
                    productCategory.DisplayOrder = model.DisplayOrder;
                    //SEO
                    productCategory.MetaDescriptions = model.MetaDescriptions;
                    productCategory.MetaKeywords     = model.MetaKeywords;
                    productCategory.ModifiedBy       = model.ModifiedBy;
                    productCategory.ModifiedDate     = DateTime.Now;

                    if (entities.SaveChanges() > 0)
                    {
                        result = GetProductCategoryById(productCategory.ID, out message);
                    }
                    else
                    {
                        message = Resources.SYSTEM_ERROR_EXECUTE_SAVECHANGE_IN_ENTITY;
                    }
                }
                else
                {
                    message = Resources.MSG_THE_PRODUCT_CATEGORY_HAS_NOT_FOUND;
                }
            }
            catch (Exception ex)
            {
                string subject = "Error " + SiteSetting.SiteName + " at Edit at ProductCategoryRepo at Model.Repository. ";
                message = StringHelper.Parameters2ErrorString(ex, model.ID);
                MailHelper.SendMail(SiteSetting.EmailAdmin, subject, message);
            }
            return(result);
        }
Exemple #17
0
        public void Save()
        {
            ProductCategoryView productView = new ProductCategoryView();

            productView.Name        = "Bilgisayar";
            productView.Description = "Bilgisayar";
            productView.ApiUserId   = Guid.NewGuid();

            productView.ProductCategoryTranslationList = new List <ProductCategoryTranslation>();
            productView.ProductCategoryTranslationList.Add(new ProductCategoryTranslation {
                Language = Enums.Language.Turkish, Name = "Bilgisayar", ProductCategoryId = productView.Id, Description = "Bilgisayar"
            });
            productView.ProductCategoryTranslationList.Add(new ProductCategoryTranslation {
                Language = Enums.Language.English, Name = "Computer", ProductCategoryId = productView.Id, Description = "Computer"
            });

            _productCategoryService.Save(productView);
            //Assert.AreNotSame(true, false);
        }
Exemple #18
0
        public ActionResult EditProduct(ProductCategoryView pcv, HttpPostedFileBase upload)
        {
            string path = Path.Combine(Server.MapPath("~/UPloads"), upload.FileName);

            upload.SaveAs(path); //file has been saved in server but not in db
            pcv.Product.Image = upload.FileName;

            var product = db.product.Single(c => c.ID == pcv.Product.ID);

            product.Name            = pcv.Product.Name;
            product.Price           = pcv.Product.Price;
            product.Image           = pcv.Product.Image;
            product.Description     = pcv.Product.Description;
            product.CategoryId      = pcv.Product.CategoryId;
            db.Entry(product).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Details", new { id = pcv.Product.ID }));
        }
Exemple #19
0
        public ActionResult Details(string id)
        {
            ProductCategoryDetailView productCategoryDetailView = new ProductCategoryDetailView();

            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("ProductCategory_Read");
            if (!hasPermission)
            {
                ModelState.AddModelError("", "AccessDenied");
                return(View(productCategoryDetailView));
            }
            #endregion

            ProductCategoryView productCategoryView = this.GetProductCategoryView(id);


            productCategoryDetailView.ProductCategoryView = productCategoryView;
            // productCategoryDetailView.EmployeeView = GetEmployee();

            return(View(productCategoryDetailView));
        }
Exemple #20
0
        public ActionResult Edit(long id = 0)
        {
            var actionStatus = new ActionResultHelper();

            actionStatus.ActionStatus = ResultSubmit.failed;
            bool IsValid = true;
            var  dao     = new ProductCategoryDao();
            ProductCategoryView model = new ProductCategoryView();

            if (id > 0)
            {
                model = dao.Find(id);
                if (model == null)
                {
                    IsValid = false;
                    actionStatus.ErrorStrings.Add(Resources.MSG_THE_PRODUCT_CATEGORY_HAS_NOT_FOUND);
                    goto actionError;
                }
                else
                {
                    ViewBag.Title = String.Format(Resources.LABEL_UPDATE, model.Name);
                    return(View(model));
                }
            }
            else
            {
                IsValid = false;
                actionStatus.ErrorStrings.Add(Resources.MSG_THE_PRODUCT_CATEGORY_HAS_NOT_FOUND);
                goto actionError;
            }
actionError:
            if (!IsValid)
            {
                actionStatus.ErrorReason             = String.Format(SiteResource.HTML_ALERT_ERROR, actionStatus.ShowErrorStrings());
                Session[SessionName.ActionStatusLog] = actionStatus;
            }

            return(RedirectToAction("Index"));
        }
        public ProductCategoryView Save(ProductCategoryView productCategoryView)
        {
            ProductCategory productCategory = this.ProductCategoryViewToProductCategory(productCategoryView);

            _productDatabaseContext.Database.BeginTransaction();
            try
            {
                productCategoryView.Id = _productCategoryRepository.Save(productCategory);
                for (int i = 0; i < productCategoryView.ProductCategoryTranslationList.Count; i++)
                {
                    productCategoryView.ProductCategoryTranslationList[i].ProductCategoryId = productCategoryView.Id;
                    productCategoryView.ProductCategoryTranslationList[i].Id = _productCategoryTranslationRepository.Save(productCategoryView.ProductCategoryTranslationList[i]);
                }
                _productDatabaseContext.Database.CommitTransaction();
            }
            catch (Exception ex)
            {
                _productDatabaseContext.Database.RollbackTransaction();
                throw;
            }
            return(productCategoryView);
        }
        public GetProductCategoryResponse GetProductCategory(GetRequest request)
        {
            GetProductCategoryResponse response = new GetProductCategoryResponse();

            try
            {
                ProductCategory     productCategory     = new ProductCategory();
                ProductCategoryView productCategoryView = productCategory.ConvertToProductCategoryView();

                productCategory = _productCategoryRepository.FindBy(request.ID);
                if (productCategory != null)
                {
                    productCategoryView = productCategory.ConvertToProductCategoryView();
                }

                response.ProductCategoryView = productCategoryView;
            }
            catch (Exception ex)
            {
            }

            return(response);
        }
Exemple #23
0
        // Product Categories
        public static void Map(this ProductCategory destination, ProductCategoryView source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            var now = DateTime.UtcNow;

            if (destination.CreatedAt == DateTimeOffset.MinValue)
            {
                destination.CreatedAt = now;
            }

            destination.Name       = source.Name;
            destination.ModifiedAt = now;
            destination.Active     = source.Active;
        }
Exemple #24
0
        public ActionResult ProductCategoryEdit(long Id = 0)
        {
            var actionStatus = new ActionResultHelper();

            actionStatus.ActionStatus = ResultSubmit.failed;
            bool IsValid = true;

            if (Id > 0)
            {
                string message            = null;
                ProductCategoryView model = _proCatRepo.GetProductCategoryById(Id, out message);
                if (model == null)
                {
                    IsValid = false;
                    actionStatus.ErrorStrings.Add(Resources.MSG_THE_PRODUCT_CATEGORY_HAS_NOT_FOUND);
                    goto actionError;
                }
                else
                {
                    ViewBag.Title = String.Format(Resources.LABEL_UPDATE, model.Name);
                    return(View(model));
                }
            }
            else
            {
                IsValid = false;
                actionStatus.ErrorStrings.Add(Resources.MSG_THE_PRODUCT_CATEGORY_HAS_NOT_FOUND);
                goto actionError;
            }
actionError:
            if (!IsValid)
            {
                actionStatus.ErrorReason = String.Format(SiteResource.HTML_ALERT_ERROR, actionStatus.ShowErrorStrings());
                Session["ACTION_STATUS"] = actionStatus;
            }
            return(RedirectToAction("ProductCategory"));
        }