Esempio n. 1
0
        public IHttpActionResult GetProductGroups(ProductGroupSearchModel model)
        {
            try
            {
                var data = GetDataList(model).Tables[0].AsEnumerable().GroupBy(g => g.Field <long>("GroupId")).Select(s => new
                {
                    Id          = s.Key,
                    Code        = s.First().Field <string>("GroupCode"),
                    Name        = s.First().Field <string>("GroupName"),
                    Description = s.First().Field <string>("Description"),
                    Price       = s.First().Field <double>("GroupSRate"),
                    Products    = s.Select(ss => new
                    {
                        Id   = ss.Field <long>("TestId"),
                        Name = ss.Field <string>("TestName"),
                        Code = ss.Field <string>("TestCode")
                    }).ToList()
                }).ToList();

                return(Ok(data));
            }
            catch (Exception ex)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)));
            }
        }
Esempio n. 2
0
        public virtual IActionResult List(ProductGroupSearchModel searchModel)
        {
            //prepare model
            var model = _productGroupModelFactory.PrepareProductGroupListModel(searchModel);

            return(Json(model));
        }
Esempio n. 3
0
        /// <summary>
        ///     Prepare product group search model
        /// </summary>
        /// <param name="searchModel">ProductGroup search model</param>
        /// <returns>ProductGroup search model</returns>
        public virtual ProductGroupSearchModel PrepareProductGroupSearchModel(ProductGroupSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Esempio n. 4
0
        private IEnumerable <ProductGroup> GetFilterProductGroups(ProductGroupSearchModel model)
        {
            try
            {
                IEnumerable <ProductGroup> data = null;


                return(data);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        private DataSet GetDataList(ProductGroupSearchModel model)
        {
            try
            {
                SqlParameter[] param =
                {
                    new SqlParameter("@companyId", model.CompanyId),
                    new SqlParameter("@id",        model.Id),
                    new SqlParameter("@search",    model.Search),
                };

                return(_spService.ExcuteSpAnonmious("[prc_getProductGroups]", param, 1));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Prepare paged productGroup list model
        /// </summary>
        /// <param name="searchModel">ProductGroup search model</param>
        /// <returns>ProductGroup list model</returns>
        public virtual ProductGroupListModel PrepareProductGroupListModel(ProductGroupSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get categories
            var categories = _productGroupService.GetAll(searchModel.ProductGroupName,
                                                         searchModel.Page - 1,
                                                         searchModel.PageSize);

            //prepare grid model
            var model = new ProductGroupListModel().PrepareToGrid(searchModel,
                                                                  categories,
                                                                  () =>
            {
                return(_mapper.Map <IList <ProductGroupModel> >(categories));
            });

            return(model);
        }
Esempio n. 7
0
        public IHttpActionResult ProductGroupSubmit(ProductGroupSearchModel model)
        {
            try
            {
                if (model.Id <= 0)
                {
                    var ProductGroupExist = _productGroupService.GetProductGroups(x => x.Name == model.Name && x.CompanyId == model.CompanyId).FirstOrDefault();

                    if (ProductGroupExist != null)
                    {
                        return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "Group name already exist.")));
                    }

                    var productGroup = new ProductGroup();
                    productGroup.Name        = model.Name;
                    productGroup.Description = model.Description;
                    productGroup.SRate       = model.SRate;
                    productGroup.Code        = GetCode(model.CompanyId);
                    productGroup.IsActive    = true;
                    productGroup.IsAdd       = true;
                    productGroup.IsUpdate    = true;
                    productGroup.IsDelete    = true;
                    productGroup.IsContinue  = true;
                    productGroup.CreatedDate = DateTime.Now;
                    productGroup.CompanyId   = model.CompanyId;

                    _productGroupService.InsertProductGroup(productGroup);


                    foreach (var item in model.Products)
                    {
                        ProductMap map = new ProductMap()
                        {
                            ProductGroupId = productGroup.Id,
                            ProductId      = item.Id
                        };

                        _productMapService.InsertProductMap(map);
                    }


                    string jsonData = JsonConvert.SerializeObject(productGroup);



                    SqlParameter[] param =
                    {
                        new SqlParameter("@logData",    jsonData),
                        new SqlParameter("@clientId",   model.CompanyId),
                        new SqlParameter("@userId",     model.CreatedBy),
                        new SqlParameter("@type",       "Insert"),
                        new SqlParameter("@action",     "ProductGroupSubmit"),
                        new SqlParameter("@controller", "ProductGroup"),
                    };

                    _spService.ExcuteSpAnonmious("prc_insertLog", param, 1);
                }
                else
                {
                    var productGroup = _productGroupService.GetProductGroupById(model.Id);

                    if (productGroup != null)
                    {
                        productGroup.Name         = model.Name;
                        productGroup.Description  = model.Description;
                        productGroup.SRate        = model.SRate;
                        productGroup.ModifiedBy   = model.CreatedBy;
                        productGroup.ModifiedDate = DateTime.Now;
                        _productGroupService.UpdateProductGroup(productGroup);



                        var maps = _productMapService.GetProductMaps(x => x.ProductGroupId == productGroup.Id).ToList();

                        foreach (var item in maps)
                        {
                            _productMapService.DeleteProductMap(item);
                        }

                        foreach (var item in model.Products)
                        {
                            ProductMap map = new ProductMap()
                            {
                                ProductGroupId = productGroup.Id,
                                ProductId      = item.Id
                            };

                            _productMapService.InsertProductMap(map);
                        }



                        string jsonData = JsonConvert.SerializeObject(model);

                        SqlParameter[] param =
                        {
                            new SqlParameter("@logData",    jsonData),
                            new SqlParameter("@clientId",   model.CompanyId),
                            new SqlParameter("@userId",     model.CreatedBy),
                            new SqlParameter("@type",       "Update"),
                            new SqlParameter("@action",     "ProductGroupSubmit"),
                            new SqlParameter("@controller", "ProductGroup"),
                        };

                        _spService.ExcuteSpAnonmious("prc_insertLog", param, 1);
                    }
                    else
                    {
                        return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "Test does not exist, please try again!")));
                    }
                }

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)));
            }
        }