Ejemplo n.º 1
0
        public ActionResult GetListFunctionProductType(int Type, List <string> ListFuncItem)
        {
            ProductDetailModels model = new ProductDetailModels();
            var data = _factory.GetProductFunctions(Type);

            data = data.Where(o => o.IsDefault == false).ToList(); /* don't get default function for addition */
            foreach (var item in data)
            {
                model.ListFunction.Add(new ProductFunctionModels
                {
                    FunctionID   = item.ID,
                    FunctionName = item.Name,
                    IsSelected   = item.IsDefault,
                });
            }
            model.ListFunction.ForEach(x =>
            {
                if (!x.IsSelected)
                {
                    x.IsSelected = ListFuncItem == null ? false : ListFuncItem.Contains(x.FunctionID);
                }
            });
            if (model.ListFunction != null)
            {
                model.ListFunction = model.ListFunction.OrderBy(x => x.FunctionName).ToList();
            }
            return(PartialView("_ListFunctionItem", model));
        }
Ejemplo n.º 2
0
        public ActionResult AddCategories(POSTDisCate data)
        {
            ProductDetailModels model = new ProductDetailModels();
            int OffSet = 0;

            if (data.ListItem != null && data.ListItem.Count > 0)
            {
                foreach (var item in data.ListItem)
                {
                    model.ListCategory.Add(new ProductCategoryModels
                    {
                        CategoryID   = item.Id,
                        CategoryName = item.Name,
                        OffSet       = OffSet++,
                        IsActive     = item.Status.ToLower().Equals("active") ? true : false,
                        Status       = (byte)Commons.EStatus.Actived,
                    });
                }
                if (model.ListCategory != null)
                {
                    model.ListCategory = model.ListCategory.OrderBy(x => x.CategoryName).ToList();
                }
            }
            return(PartialView("_ListAddCate", model));
        }
Ejemplo n.º 3
0
        public ActionResult AddItems(POSTItem data)
        {
            ProductDetailModels model = new ProductDetailModels();
            int OffSet = 0;

            if (data.ListItem != null && data.ListItem.Count > 0)
            {
                List <ProductCompositeModels> listData = new List <ProductCompositeModels>();
                foreach (var item in data.ListItem)
                {
                    listData.Add(new ProductCompositeModels
                    {
                        ProductID    = item.ProductID,
                        CategoryName = item.CategoryName,
                        TypeName     = item.TypeName,
                        ProductName  = item.ProductName,
                        ProductType  = item.ProductType,
                        Quantity     = item.IsUnlimited ? -1 : item.Quantity,
                        Sequence     = item.Sequence,
                        AdditionType = item.AdditionType,
                        IsSelect     = item.IsSelect,
                        IsUnlimited  = item.IsUnlimited,
                        OffSet       = OffSet++,
                        //IsSelect = item.Status.Equals("active") ? true : false,
                        Status = (byte)Commons.EStatus.Actived,
                    });
                }
                if (listData != null)
                {
                    listData = listData.OrderBy(x => x.ProductName).ToList();
                }
                model.ListComposite = listData;
            }
            return(PartialView("_ListItem", model));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Result will return Product
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public ProductDetailModels GetDetail(string ID)
        {
            ProductDetailModels item = new ProductDetailModels();

            try
            {
                ProductRequest paraBody = new ProductRequest();
                paraBody.ID = ID;

                NSLog.Logger.Info("ProductDetail Request: ", paraBody);

                var     result     = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.ProductAPIGetDetail, null, paraBody);
                dynamic data       = result.Data;
                var     lstDataRaw = data["ProductDetail"];
                var     lstObject  = JsonConvert.SerializeObject(lstDataRaw);
                item = JsonConvert.DeserializeObject <ProductDetailModels>(lstObject);
                if (item != null)
                {
                    item.SaleFrom = CommonHelper.ConvertToLocalTime(item.SaleFrom);
                    item.SaleTo   = CommonHelper.ConvertToLocalTime(item.SaleTo);
                }
                NSLog.Logger.Info("ProductGetDetail", item);

                return(item);
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("ProductGetDetail_Fail", e);
                return(item);
            }
        }
Ejemplo n.º 5
0
        public ActionResult GetListServices(ProductDetailModels model)
        {
            try
            {
                string SearchString  = "";
                var    _ProductType  = (int)Commons.EProductType.Addition;
                var    _AdditionType = (int)Commons.EAdditionType.Service;
                var    _Products     = _factory.GetListData(SearchString, _ProductType)
                                       .Where(x => x.AdditionType == _AdditionType)
                                       .Select(x => new ProductModels
                {
                    ProductType  = x.ProductType,
                    Name         = x.Name,
                    ID           = x.ID,
                    Quantity     = x.Quantity.HasValue ? x.Quantity.Value : 1,
                    Sequence     = x.Sequence.HasValue ? x.Sequence.Value : 0,
                    AdditionType = x.AdditionType,
                    CategoryName = Commons.EAdditionType.Service.ToString()
                })
                                       .ToList();
                /****** Add Code Products *****/
                //_Products = new List<ProductModels>()
                //{
                //    new ProductModels { ID = "40b849b9-5f50-48f8-9546-c7161f465a68", ProductType = 2, AdditionType = 3, Name = "Ipad Mini" , IsSelect = false, Quantity = 0 , Sequence = 0, CategoryName="Hardware"},
                //    new ProductModels { ID = "28734388-5b92-4ddc-b583-5a304df8954a", ProductType = 2, AdditionType = 3, Name = "Printer HP", IsSelect = false, Quantity = 0 , Sequence = 0,CategoryName="Hardware" },
                //};

                /**** List Id Composite ****/
                var CompositeIds = model.ListComposite
                                   .Where(x => x.AdditionType == _AdditionType)
                                   .Select(x => x.ProductID).ToList();

                /***** Comparse exits Product and Composite *****/
                _Products.Where(x => CompositeIds.Contains(x.ID)).Select(x => x).ToList()
                .ForEach(x =>
                {
                    x.IsSelect = true;
                    x.Quantity = model.ListComposite.FirstOrDefault(y => y.ProductID == x.ID) != null ? model.ListComposite.FirstOrDefault(y => y.ProductID == x.ID).Quantity : 1;
                    x.Sequence = model.ListComposite.FirstOrDefault(y => y.ProductID == x.ID) != null ? model.ListComposite.FirstOrDefault(y => y.ProductID == x.ID).Sequence : 0;
                });


                if (model == null)
                {
                    model = new ProductDetailModels();
                }
                model.ListProducts = _Products;

                return(PartialView("_ItemModalCompositeServices", model));
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("GetListHardware : ", e);
                return(new HttpStatusCodeResult(400, e.Message));
            }
        }
Ejemplo n.º 6
0
        public new PartialViewResult View(string id)
        {
            ProductDetailModels model = GetDetail(id);

            // Don't show default function for addition
            if (model.ListFunction != null && model.ListFunction.Any())
            {
                model.ListFunction = model.ListFunction.Where(w => w.IsDefault == false).ToList();
            }
            return(PartialView("_View", model));
        }
Ejemplo n.º 7
0
 public ActionResult SetActiveUnActivePriceItem(string Id, ProductDetailModels model, bool IsActive)
 {
     try
     {
         model.ListPrice.Where(x => x.ID == Id).ToList().ForEach(x => x.IsActive = IsActive);
         return(PartialView("_ItemModalPriceItems", model));
     }catch (Exception ex)
     {
         NSLog.Logger.Error("SetActiveUnActivePriceItem : ", ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
Ejemplo n.º 8
0
 public ActionResult SaveComposite(ProductDetailModels model)
 {
     try
     {
         model.ListComposite.OrderBy(x => x.Sequence).ToList();
         return(PartialView("_ItemModalComposite", model));
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("SaveComposite : ", ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
Ejemplo n.º 9
0
        public ActionResult GetListHardware(ProductDetailModels model, bool IsCreate = false)
        {
            try
            {
                string SearchString  = "";
                var    _ProductType  = (int)Commons.EProductType.Addition;
                var    _AdditionType = (int)Commons.EAdditionType.Hardware;
                var    _Products     = _factory.GetListData(SearchString, _ProductType)
                                       .Where(x => x.AdditionType == _AdditionType ||
                                              x.AdditionType == (int)Commons.EAdditionType.Service)
                                       .OrderBy(x => x.AdditionType)
                                       .Select(x => new ProductModels
                {
                    ProductType  = x.ProductType,
                    Name         = x.Name,
                    ID           = x.ID,
                    Quantity     = x.Quantity.HasValue ? x.Quantity.Value : 1,
                    Sequence     = x.Sequence.HasValue ? x.Sequence.Value : 0,
                    AdditionType = x.AdditionType,
                    //CategoryName = Commons.EAdditionType.Hardware.ToString()
                })

                                       .ToList();

                /**** List Id Composite ****/
                var CompositeIds = model.ListComposite
                                   .Select(x => x.ProductID).ToList();

                /***** Comparse exits Product and Composite *****/
                _Products.Where(x => CompositeIds.Contains(x.ID)).Select(x => x).ToList()
                .ForEach(x =>
                {
                    x.IsSelect = true;
                    x.Quantity = model.ListComposite.FirstOrDefault(y => y.ProductID == x.ID) != null ? model.ListComposite.FirstOrDefault(y => y.ProductID == x.ID).Quantity : 1;
                    x.Sequence = model.ListComposite.FirstOrDefault(y => y.ProductID == x.ID) != null ? model.ListComposite.FirstOrDefault(y => y.ProductID == x.ID).Sequence : 0;
                });
                if (model == null)
                {
                    model = new ProductDetailModels();
                }
                model.ListProducts = _Products;

                return(PartialView("_ItemModalCompositeHardware", model));
            }catch (Exception e)
            {
                NSLog.Logger.Error("GetListHardware : ", e);
                return(new HttpStatusCodeResult(400, e.Message));
            }
        }
Ejemplo n.º 10
0
        //[HttpGet]
        //public PartialViewResult Delete(string id)
        //{
        //    ProductDetailModels model = GetDetail(id);
        //    return PartialView("_Delete", model);
        //}
        //[HttpPost]
        //public ActionResult Delete(ProductModels model)
        //{
        //    try
        //    {
        //        string msg = "";
        //        var result = _factory.Delete(model.ID, CurrentUser.UserId, ref msg);
        //        if (!result)
        //        {
        //            ModelState.AddModelError("Name", Commons.ErrorMsg /*msg*/);
        //            Response.StatusCode = (int)HttpStatusCode.BadRequest;
        //            return PartialView("_Delete", model);
        //        }
        //        return new HttpStatusCodeResult(HttpStatusCode.OK);
        //    }
        //    catch (Exception ex)
        //    {
        //        NSLog.Logger.Error("ProductPackageDelete: ", ex);
        //        ModelState.AddModelError("Name", "Have an error when you delete a package");
        //        Response.StatusCode = (int)HttpStatusCode.BadRequest;
        //        return PartialView("_Delete", model);
        //    }
        //}

        public ActionResult LoadItems(byte Eproducttype, byte EAdditionType)
        {
            ProductDetailModels model = new ProductDetailModels();
            var Data = _factory.GetListData(null, Eproducttype);

            if (Eproducttype == (byte)Commons.EProductType.Addition)
            {
                Data = Data.Where(x => x.AdditionType == (byte)Commons.EAdditionType.Hardware || x.AdditionType == (byte)Commons.EAdditionType.Service).ToList();
                //Data.ForEach(x =>
                //{
                //    x.CategoryName = x.AdditionType == (byte)Commons.EAdditionType.Hardware ? Commons.EAdditionType.Hardware.ToString() : Commons.EAdditionType.Service.ToString();
                //});
            }
            int OffSet = 0;

            foreach (var item in Data)
            {
                string typeName = "";
                if (item.ProductType == (byte)Commons.EProductType.Product)
                {
                    typeName = ((Commons.EType)Enum.ToObject(typeof(Commons.EType), item.Type)).ToString().Replace("_", " ");
                }
                else if (item.ProductType == (byte)Commons.EProductType.Addition)
                {
                    typeName = ((Commons.EAdditionType)Enum.ToObject(typeof(Commons.EAdditionType), item.AdditionType)).ToString();
                }
                model.ClientListProduct.Add(new ProductCompositeModels
                {
                    CategoryName = item.CategoryName,
                    TypeName     = typeName,
                    ProductName  = item.Name,
                    ProductID    = item.ID,
                    AdditionType = item.AdditionType,
                    ProductType  = Eproducttype,
                    Sequence     = 0,
                    Quantity     = 1,
                    Status       = item.IsActive ? 1 : 0,
                    IsSelect     = false,
                    IsUnlimited  = false,
                    OffSet       = OffSet++,
                });
            }
            if (model.ClientListProduct != null)
            {
                model.ClientListProduct = model.ClientListProduct.OrderBy(x => x.ProductName).ToList();
            }
            return(PartialView("_ListProduct", model));
        }
Ejemplo n.º 11
0
 public ActionResult Search()
 {
     try
     {
         string SearchString       = "";
         ProductDetailModels model = new ProductDetailModels();
         var _ProductType          = (int)Commons.EProductType.Product;
         model.ListProducts = _factory.GetListData(SearchString, _ProductType);
         return(PartialView("_ListData", model));
     }
     catch (Exception e)
     {
         NSLog.Logger.Error("Search :", e);
         return(new HttpStatusCodeResult(400, e.Message));
     }
 }
Ejemplo n.º 12
0
 public ActionResult DeleteComposite(string Id, ProductDetailModels model)
 {
     try
     {
         if (model != null && model.ListComposite != null && model.ListComposite.Count > 0)
         {
             var _Composite = model.ListComposite.FirstOrDefault(x => x.ProductID == Id);
             model.ListComposite.Remove(_Composite);
         }
         return(PartialView("_ItemModalComposite", model));
     }catch (Exception ex)
     {
         NSLog.Logger.Error("DeleteComposite : ", ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
Ejemplo n.º 13
0
        public ActionResult Create()
        {
            ProductDetailModels model = new ProductDetailModels();

            try
            {
                var _user = Session["User"] as UserSession;
                if (_user == null)
                {
                    return(RedirectToAction("Index", "Login", new { area = "" }));
                }
                else
                {
                    CategoriesFactory _cateFactory = new CategoriesFactory();
                    var lstCategory = _cateFactory.GetListCategory(_user.UserId);
                    lstCategory = lstCategory.OrderBy(o => o.Name).ThenBy(o => o.Id).ToList();
                    var _categories = lstCategory
                                      .Where(x => x.IsActive)
                                      .Select(x => new SelectListItem
                    {
                        Value = x.Id,
                        Text  = x.Name
                    })
                                      .ToList();
                    model.Categories = _categories;

                    var Type = lstCategory != null?lstCategory.Where(x => x.IsActive).FirstOrDefault().Type : 0;

                    var lstFunction = _factory.GetProductFunctions(Type).OrderBy(o => o.Name).Select(x => new ProductFunctionModels
                    {
                        FunctionID   = x.ID,
                        FunctionName = x.Name,
                        IsDefault    = x.IsDefault,
                        IsSelected   = x.IsDefault ? true : false
                    })
                                      .ToList();
                    model.ListFunction = lstFunction;
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Create: ", ex);
            }

            return(View(model));
        }
Ejemplo n.º 14
0
        public JsonResult GetDetailExtendPriceItem(string Id, ProductDetailModels model)
        {
            var _Product = new ProductPriceModels();

            try
            {
                if (model != null && model.ListPriceExtend != null && model.ListPriceExtend.Count > 0)
                {
                    _Product = model.ListPriceExtend.FirstOrDefault(x => x.ID == Id && x.IsExtend);
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("GetDetailExtendPriceItem : ", ex);
            }
            return(Json(_Product));
        }
Ejemplo n.º 15
0
        public ActionResult AddEditPriceItem(ProductPriceModels ProductPrice, List <ProductPriceModels> ProductDetailModels)
        {
            try
            {
                if (ProductDetailModels == null)
                {
                    ProductDetailModels = new List <ProductPriceModels>();
                }

                var IsEdit = false;
                if (ProductPrice != null && !string.IsNullOrEmpty(ProductPrice.ID) &&
                    ProductDetailModels != null && ProductDetailModels.Count > 0)
                {
                    IsEdit = ProductDetailModels.Any(x => x.ID == ProductPrice.ID && !x.IsExtend);
                }

                if (IsEdit)
                {
                    ProductDetailModels.Where(x => x.ID == ProductPrice.ID && !x.IsExtend)
                    .Select(x => x).ToList()
                    .ForEach(x =>
                    {
                        x.Price      = ProductPrice.Price;
                        x.Period     = ProductPrice.Period;
                        x.PeriodType = ProductPrice.PeriodType;
                    });
                }
                else
                {
                    //ProductPrice.OffSet = model.ListPrice.Max(x => x.OffSet) + 1;
                    ProductPrice.ID       = Guid.NewGuid().ToString();
                    ProductPrice.IsExtend = false;
                    ProductPrice.IsActive = true;
                    ProductPrice.IsNew    = true;
                    ProductDetailModels.Add(ProductPrice);
                }
                ProductDetailModels model = new ProductDetailModels();
                model.ListPrice.AddRange(ProductDetailModels);
                return(PartialView("_ItemModalPriceItems", model));
            }catch (Exception e)
            {
                NSLog.Logger.Error("AddPriceItem :", e);
                return(new HttpStatusCodeResult(400, e.Message));
            }
        }
Ejemplo n.º 16
0
 public ActionResult DeleteExtendPriceItem(string Id, ProductDetailModels model)
 {
     try
     {
         if (model != null && model.ListPriceExtend != null && model.ListPriceExtend.Count > 0)
         {
             var _Product = model.ListPriceExtend.FirstOrDefault(x => x.ID == Id && x.IsExtend);
             if (_Product != null)
             {
                 model.ListPriceExtend.Remove(_Product);
             }
         }
         return(PartialView("_ItemModalExtendPriceItems", model));
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("DeleteExtendPriceItem :", ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Create Or Edit Product
        /// </summary>
        /// <param name="model"></param>
        /// <param name="msg"></param>
        /// <returns> return value type bool </returns>
        public bool CreateOrEdit(ProductDetailModels model, ref string msg)
        {
            try
            {
                ProductRequest paraBody = new ProductRequest();
                model.SaleFrom = CommonHelper.ConvertToUTCTime(model.SaleFrom);
                model.SaleTo   = CommonHelper.ConvertToUTCTime(model.SaleTo);

                paraBody.ProductDetail = model;
                paraBody.CreatedUser   = model.CreateUser;

                NSLog.Logger.Info("ProductCreateOrEdit Request: ", paraBody);
                //====================
                var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.ProductAPICreateOrEdit, null, paraBody);
                if (result != null)
                {
                    if (result.Success)
                    {
                        return(true);
                    }
                    else
                    {
                        msg = result.Message;
                        NSLog.Logger.Info("ProductCreateOrEdit", result.Message);
                        return(false);
                    }
                }
                else
                {
                    NSLog.Logger.Info("ProductCreateOrEdit", result);
                    return(false);
                }
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("ProductCreateOrEdit_Fail", e);
                return(false);
            }
        }
Ejemplo n.º 18
0
 public ActionResult Delete(ProductDetailModels model)
 {
     try
     {
         string msg    = "";
         var    result = _factory.Delete(model.ID, CurrentUser.UserId, ref msg);
         if (!result)
         {
             ModelState.AddModelError("Name", msg);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Delete", model));
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("ProductDelete: ", ex);
         ModelState.AddModelError("Name", "Have an error when you delete a Products");
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
Ejemplo n.º 19
0
        //[HttpGet]
        //public PartialViewResult Delete(string id)
        //{
        //    ProductDetailModels model = GetDetail(id);
        //    return PartialView("_Delete", model);
        //}
        //[HttpPost]
        //public ActionResult Delete(ProductDetailModels model)
        //{
        //    try
        //    {
        //        string msg = "";
        //        var result = _factory.Delete(model.ID, CurrentUser.UserId, ref msg);
        //        if (!result)
        //        {
        //            ModelState.AddModelError("Name", Commons.ErrorMsg /*msg*/);
        //            Response.StatusCode = (int)HttpStatusCode.BadRequest;
        //            return PartialView("_Delete", model);
        //        }
        //        return new HttpStatusCodeResult(HttpStatusCode.OK);
        //    }
        //    catch (Exception ex)
        //    {
        //        NSLog.Logger.Error("ProductDelete: ", ex);
        //        ModelState.AddModelError("Name", "Have an error when you delete a addition");
        //        Response.StatusCode = (int)HttpStatusCode.BadRequest;
        //        return PartialView("_Delete", model);
        //    }
        //}

        public ActionResult LoadCategories()
        {
            ProductDetailModels model = new ProductDetailModels();
            var DataCate = _facCate.GetListCategory(CurrentUser.UserId);
            int OffSet   = 0;

            foreach (var item in DataCate.Where(x => !x.IsFreeTrial))
            {
                model.ClientListDisCate.Add(new ItemDisCate
                {
                    Name     = item.Name,
                    Id       = item.Id,
                    IsSelect = false,
                    Status   = item.IsActive ? "Active" : "Inactive",
                    OffSet   = OffSet++,
                });
            }
            if (model.ClientListDisCate != null)
            {
                model.ClientListDisCate = model.ClientListDisCate.OrderBy(x => x.Name).ToList();
            }
            return(PartialView("_ListCategoy", model));
        }
Ejemplo n.º 20
0
        public ProductDetailModels GetDetail(string id)
        {
            try
            {
                ProductDetailModels model = _factory.GetDetail(id);
                int OffSet = 0;
                if (model.ListCategory != null)
                {
                    model.ListCategory.ForEach(x =>
                    {
                        x.OffSet = OffSet++;
                        if (x.Status == 0)
                        {
                            x.Status = (byte)Commons.EStatus.Actived;
                        }
                    });
                    model.ListCategory = model.ListCategory.OrderBy(x => x.CategoryName).ToList();
                }
                //=================
                OffSet = 0;
                if (model.ListPrice != null)
                {
                    model.ListPrice.ForEach(x =>
                    {
                        x.OffSet = OffSet++;
                        if (x.Status == 0)
                        {
                            x.Status = (byte)Commons.EStatus.Actived;
                        }
                        //=============
                        if (x.PeriodType == (byte)Commons.EPeriodType.Day)
                        {
                            x.NamePeriodType = Commons.EPeriodType.Day.ToString();
                        }
                        else if (x.PeriodType == (byte)Commons.EPeriodType.Month)
                        {
                            x.NamePeriodType = Commons.EPeriodType.Month.ToString();
                        }
                        else if (x.PeriodType == (byte)Commons.EPeriodType.None)
                        {
                            x.NamePeriodType = Commons.EPeriodType.None.ToString();
                        }
                        else if (x.PeriodType == (byte)Commons.EPeriodType.OneTime)
                        {
                            x.NamePeriodType = Commons.EPeriodType.OneTime.ToString().Insert(3, " ");
                        }
                        else if (x.PeriodType == (byte)Commons.EPeriodType.Year)
                        {
                            x.NamePeriodType = Commons.EPeriodType.Year.ToString();
                        }
                    });
                    model.ListPrice = model.ListPrice.OrderBy(x => x.Period).ToList();
                }

                //Get CategoryName from AdditionType
                if (model.AdditionType == (byte)Commons.EAdditionType.Hardware)
                {
                    model.CategoryName = Commons.EAdditionType.Hardware.ToString();
                }
                else if (model.AdditionType == (byte)Commons.EAdditionType.Location)
                {
                    model.CategoryName = Commons.EAdditionType.Location.ToString();
                }
                else if (model.AdditionType == (byte)Commons.EAdditionType.Service)
                {
                    model.CategoryName = Commons.EAdditionType.Service.ToString();
                }
                else if (model.AdditionType == (byte)Commons.EAdditionType.Software)
                {
                    model.CategoryName = Commons.EAdditionType.Software.ToString();
                }
                else if (model.AdditionType == (byte)Commons.EAdditionType.Account)
                {
                    model.CategoryName = Commons.EAdditionType.Account.ToString();
                }
                else if (model.AdditionType == (byte)Commons.EAdditionType.Function)
                {
                    model.CategoryName = Commons.EAdditionType.Function.ToString();
                }

                return(model);
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("ProductAdditionDetail: ", ex);
                return(null);
            }
        }
Ejemplo n.º 21
0
        public ActionResult Create(ProductDetailModels model)
        {
            try
            {
                if (model.SaleFrom > model.SaleTo)
                {
                    ModelState.AddModelError("DateSaleValidate", "From Date must be less than To Date.");
                }
                if (model.PictureUpload != null && !Commons.ImageExtendFiler.Contains(model.PictureUpload.ContentType))
                {
                    ModelState.AddModelError("PictureUpload", Commons.ErrorMsgFilterImage);
                }
                //==========Composite
                model.ListComposite = model.ListComposite.Where(x => x.Status != (byte)Commons.EStatus.Deleted).ToList();
                model.ListComposite.ForEach(x =>
                {
                    if (x.IsUnlimited)
                    {
                        x.Quantity = -1;
                    }
                });
                //==========Price
                model.ListPrice       = model.ListPrice.Where(x => x.Status != (byte)Commons.EStatus.Deleted).ToList();
                model.ListPriceExtend = model.ListPriceExtend.Where(x => x.Status != (byte)Commons.EStatus.Deleted).ToList();
                model.ListPrice.AddRange(model.ListPriceExtend);

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                byte[] photoByte = null;
                if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte = new Byte[model.PictureUpload.ContentLength];
                    model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength);
                    model.PictureByte   = imgByte;
                    model.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName);
                    model.PictureUpload = null;
                    photoByte           = imgByte;
                }
                //==============
                model.CreateUser  = CurrentUser.UserId;
                model.ProductType = (byte)Commons.EProductType.Package;
                string msg = "";
                var    tmp = model.PictureByte;
                model.PictureByte = null;
                bool result = _factory.CreateOrEdit(model, ref msg);
                if (result)
                {
                    model.PictureByte = tmp;
                    if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null)
                    {
                        var          originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\")));
                        var          path = string.Format("{0}{1}", originalDirectory, model.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte, 0, photoByte.Length);
                        ms.Write(photoByte, 0, photoByte.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);
                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte);
                        model.PictureByte = photoByte;
                        FTP.Upload(model.ImageURL, model.PictureByte);
                        ImageHelper.Me.TryDeleteImageUpdated(path);
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //return RedirectToAction("Create");
                    //ModelState.AddModelError("Name", Commons.ErrorMsg /*msg*/);
                    ModelState.AddModelError("Error", msg);
                    model.ListPrice = model.ListPrice.Where(w => w.IsExtend == false).ToList();
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("ProductPackageCreate: ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
Ejemplo n.º 22
0
        public ActionResult Create()
        {
            ProductDetailModels model = new ProductDetailModels();

            return(View(model));
        }
Ejemplo n.º 23
0
        public ActionResult Create(ProductDetailModels model)
        {
            try
            {
                if (model.AdditionType == (int)Commons.EAdditionType.Function)
                {
                    var lstseletedFunction = model.ListFunction.Where(x => x.IsSelected == true).ToList();
                    if (lstseletedFunction.Count < 1)
                    {
                        ModelState.AddModelError("Error", "Unable to save this additional function. At least one function must be selected.");
                    }
                }
                if (model.SaleFrom > model.SaleTo)
                {
                    ModelState.AddModelError("SaleFrom", "From Date must be less than To Date.");
                }
                model.ListCategory = model.ListCategory.Where(x => x.Status != (byte)Commons.EStatus.Deleted).ToList();
                model.ListPrice    = model.ListPrice.Where(x => x.Status != (byte)Commons.EStatus.Deleted).ToList();
                if (model.PictureUpload != null && !Commons.ImageExtendFiler.Contains(model.PictureUpload.ContentType))
                {
                    ModelState.AddModelError("PictureUpload", Commons.ErrorMsgFilterImage);
                }
                if (!ModelState.IsValid)
                {
                    //if ((ModelState["PictureUpload"]) != null && (ModelState["PictureUpload"]).Errors.Count > 0)
                    //    model.ImageURL = "";
                    //model.ImageURL = Commons.Image100_100;
                    return(View(model));
                }

                byte[] photoByte = null;
                if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte = new Byte[model.PictureUpload.ContentLength];
                    model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength);
                    model.PictureByte   = imgByte;
                    model.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName);
                    model.PictureUpload = null;
                    photoByte           = imgByte;
                }

                //============
                model.CreateUser  = CurrentUser.UserId;
                model.ProductType = (byte)Commons.EProductType.Addition;
                string msg    = "";
                bool   result = _factory.CreateOrEdit(model, ref msg);
                if (result)
                {
                    if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null)
                    {
                        var          originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\")));
                        var          path = string.Format("{0}{1}", originalDirectory, model.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte, 0, photoByte.Length);
                        ms.Write(photoByte, 0, photoByte.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);
                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte);
                        model.PictureByte = photoByte;
                        FTP.Upload(model.ImageURL, model.PictureByte);
                        ImageHelper.Me.TryDeleteImageUpdated(path);
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //return RedirectToAction("Create");
                    //ModelState.AddModelError("Name", Commons.ErrorMsg /*msg*/);
                    ModelState.AddModelError("Error", msg);
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("ProductAdditionCreate: ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
Ejemplo n.º 24
0
        public PartialViewResult Edit(string id)
        {
            ProductDetailModels model = GetDetail(id);

            return(PartialView("_Edit", model));
        }
Ejemplo n.º 25
0
        public new PartialViewResult View(string id)
        {
            ProductDetailModels model = GetDetail(id);

            return(PartialView("_View", model));
        }
Ejemplo n.º 26
0
        public ProductDetailModels GetDetail(string id)
        {
            try
            {
                ProductDetailModels model = _factory.GetDetail(id);
                //==========Price
                List <ProductPriceModels> listPrice = model.ListPrice;
                listPrice.ForEach(x =>
                {
                    if (x.Status == 0)
                    {
                        x.Status = (byte)Commons.EStatus.Actived;
                    }
                    if (x.PeriodType == (byte)Commons.EPeriodType.Day)
                    {
                        x.NamePeriodType = Commons.EPeriodType.Day.ToString();
                    }
                    else if (x.PeriodType == (byte)Commons.EPeriodType.Month)
                    {
                        x.NamePeriodType = Commons.EPeriodType.Month.ToString();
                    }
                    else if (x.PeriodType == (byte)Commons.EPeriodType.None)
                    {
                        x.NamePeriodType = Commons.EPeriodType.None.ToString();
                    }
                    else if (x.PeriodType == (byte)Commons.EPeriodType.OneTime)
                    {
                        x.NamePeriodType = Commons.EPeriodType.OneTime.ToString().Insert(3, " ");
                    }
                    else if (x.PeriodType == (byte)Commons.EPeriodType.Year)
                    {
                        x.NamePeriodType = Commons.EPeriodType.Year.ToString();
                    }
                });

                //======ListPrice
                int OffSet = 0;
                model.ListPrice = listPrice.Where(x => !x.IsExtend).OrderBy(x => x.Period).ToList();
                model.ListPrice.ForEach(x =>
                {
                    x.OffSet = OffSet++;
                });
                //=====ListPriceExtend
                OffSet = 0;
                model.ListPriceExtend = listPrice.Where(x => x.IsExtend).OrderBy(x => x.Period).ToList();
                model.ListPriceExtend.ForEach(x =>
                {
                    x.OffSet = OffSet++;
                });
                //==================Composite
                OffSet = 0;
                List <ProductCompositeModels> ListComposite = model.ListComposite;
                ListComposite.ForEach(x =>
                {
                    x.OffSet = OffSet++;

                    if (x.Status == 0)
                    {
                        x.Status = (byte)Commons.EStatus.Actived;
                    }

                    //if (x.ProductType == (byte)Commons.EProductType.Addition)
                    //{
                    //    if (x.AdditionType == (byte)Commons.EAdditionType.Hardware)
                    //        x.CategoryName = Commons.EAdditionType.Hardware.ToString();
                    //    else if (x.AdditionType == (byte)Commons.EAdditionType.Service)
                    //        x.CategoryName = Commons.EAdditionType.Service.ToString();
                    //}
                    if (x.ProductType == (byte)Commons.EProductType.Product)
                    {
                        x.CategoryName   = x.ListCategory.Select(s => s.CategoryName).FirstOrDefault().ToString();
                        int categoryType = x.ListCategory.Select(s => s.Type).FirstOrDefault();
                        x.TypeName       = ((Commons.EType)Enum.ToObject(typeof(Commons.EType), categoryType)).ToString().Replace("_", " ");
                    }
                    else if (x.ProductType == (byte)Commons.EProductType.Addition)
                    {
                        x.TypeName = ((Commons.EAdditionType)Enum.ToObject(typeof(Commons.EAdditionType), x.AdditionType)).ToString();
                    }

                    if (x.Quantity == -1)
                    {
                        x.IsUnlimited = true;
                    }
                });
                model.ListComposite = ListComposite.OrderBy(x => x.ProductName).ToList();

                return(model);
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("ProductPackageDetail: ", ex);
                return(null);
            }
        }
Ejemplo n.º 27
0
        public ActionResult Edit(ProductDetailModels model)
        {
            string _CurrentURL = model.ImageURL;

            try
            {
                CategoriesFactory _cateFactory = new CategoriesFactory();
                //var _categories = _cateFactory.GetListCategory(CurrentUser.UserId)
                //                                .Where(x => x.IsActive)
                //                                .Select(x => new SelectListItem
                //                                {
                //                                    Value = x.Id,
                //                                    Text = x.Name
                //                                })
                //                                .ToList();
                //model.Categories = _categories;
                var _categories = _cateFactory.GetListCategory(CurrentUser.UserId);
                //Can not change category has different type with the old category.
                int curCateType   = _categories.Where(w => w.Id == model.CategoryId).Select(s => s.Type).FirstOrDefault();
                var lstCategories = new List <SelectListItem>();
                lstCategories = _categories.Where(x => x.IsActive && x.Type == curCateType && x.Id != model.CategoryId)
                                .Select(x => new SelectListItem
                {
                    Value = x.Id,
                    Text  = x.Name
                })
                                .ToList();
                lstCategories.Add(new SelectListItem
                {
                    Value = model.CategoryId,
                    Text  = model.CategoryName
                });
                model.Categories = lstCategories;
                if (string.IsNullOrEmpty(model.Name))
                {
                    ModelState.AddModelError("Name", "The Name field is required");
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }

                if (string.IsNullOrEmpty(model.Code))
                {
                    ModelState.AddModelError("Code", "The Code field is required");
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }

                if (string.IsNullOrEmpty(model.CategoryId))
                {
                    ModelState.AddModelError("CategoryId", "The Category field is required");
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
                if (model.PictureUpload != null && !Commons.ImageExtendFiler.Contains(model.PictureUpload.ContentType))
                {
                    ModelState.AddModelError("PictureUpload", Commons.ErrorMsgFilterImage);
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
                if (model.SaleFrom > model.SaleTo)
                {
                    ModelState.AddModelError("SaleFrom", "From Date must be less than To Date.");
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }

                if (model.ListPrice == null || (model.ListPrice != null && model.ListPrice.Count == 0))
                {
                    ModelState.AddModelError("ListPrice", "The Price Items is required");
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }



                //if (model.ListPrice != null && model.ListPrice.Count > 0)
                //{
                //    var isExistActive = model.ListPrice.Any(x => x.IsActive);
                //    if (!isExistActive)
                //    {
                //        ModelState.AddModelError("ListPrice", "Please enter a price item greater than or equal to 1 is active");
                //        Response.StatusCode = (int)HttpStatusCode.BadRequest;
                //        return PartialView("_Edit", model);
                //    }
                //}

                //if (model.IsExtend && (model.ListPriceExtend == null ||(model.ListPriceExtend != null && model.ListPriceExtend.Count == 0)))
                //{
                //    ModelState.AddModelError("ListPriceExtend", "The Extend Price Items is requered");
                //    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                //    return PartialView("_Edit", model);
                //}

                if (!ModelState.IsValid)
                {
                    if ((ModelState["PictureUpload"]) != null && (ModelState["PictureUpload"]).Errors.Count > 0)
                    {
                        model.ImageURL = "";
                    }
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }

                if (string.IsNullOrEmpty(model.ImageURL))
                {
                    model.ImageURL = model.ImageURL.Replace(Commons.PublicImages, "").Replace(Commons.Image100_100, "");
                }
                /*** Processing Image *****/
                byte[] photoByte = null;
                if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte = new Byte[model.PictureUpload.ContentLength];
                    model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength);
                    model.PictureByte   = imgByte;
                    model.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName);
                    model.PictureUpload = null;
                    photoByte           = imgByte;
                }
                else
                {
                    model.ImageURL = model.ImageURL.Replace(Commons.PublicImages, "").Replace(Commons.Image100_100, "");
                }
                /*** End Processing Image ****/
                string msg = "";
                model.CreateUser  = CurrentUser.UserId;
                model.ProductType = (int)Commons.EProductType.Product;
                if (model.ListCategory == null)
                {
                    model.ListCategory = new List <ProductCategoryModels>();
                }

                model.ListCategory.Add(new ProductCategoryModels
                {
                    CategoryID = model.CategoryId
                });
                model.ListPrice.AddRange(model.ListPriceExtend);
                model.ListPrice.Where(x => x.IsNew).ToList().ForEach(x => x.ID = null);
                var tmp = model.PictureByte;
                model.PictureByte = null;
                if (model.ListFunction != null && model.ListFunction.Count > 0)
                {
                    model.ListFunction.Where(x => x.IsDefault).ToList().ForEach(x => x.IsSelected = true);
                }
                bool result = _factory.CreateOrEdit(model, ref msg);
                if (result)
                {
                    model.PictureByte = tmp;
                    if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null)
                    {
                        var          originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\")));
                        var          path = string.Format("{0}{1}", originalDirectory, model.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte, 0, photoByte.Length);
                        ms.Write(photoByte, 0, photoByte.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);
                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte);
                        model.PictureByte = photoByte;
                        FTP.Upload(model.ImageURL, model.PictureByte);
                        ImageHelper.Me.TryDeleteImageUpdated(path);
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //ModelState.AddModelError("Name", Commons.ErrorMsg);
                    ModelState.AddModelError("Error", msg);
                    model.ImageURL  = _CurrentURL;
                    model.ListPrice = model.ListPrice.Where(w => w.IsExtend == false).ToList();
                    model.ListPrice.Where(x => x.IsNew).ToList().ForEach(x => x.ID = Guid.NewGuid().ToString());
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Edit :", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }