Exemplo n.º 1
0
        public IActionResult Post(CatCommodityGroupEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var checkExistMessage = CheckExist(0, model);

            if (checkExistMessage.Length > 0)
            {
                return(BadRequest(new ResultHandle {
                    Status = false, Message = checkExistMessage
                }));
            }
            var catCommodityGroup = mapper.Map <CatCommodityGroupModel>(model);

            catCommodityGroup.UserCreated     = currentUser.UserID;
            catCommodityGroup.DatetimeCreated = catCommodityGroup.DatetimeModified = DateTime.Now;
            catCommodityGroup.Active          = true;
            var          hs      = catComonityGroupService.Add(catCommodityGroup);
            var          message = HandleError.GetMessage(hs, Crud.Insert);
            ResultHandle result  = new ResultHandle {
                Status = hs.Success, Message = stringLocalizer[message].Value
            };

            if (!hs.Success)
            {
                return(BadRequest(result));
            }
            catComonityGroupService.ClearCache();
            catComonityGroupService.Get();
            return(Ok(result));
        }
Exemplo n.º 2
0
        public IQueryable <CatCommodityModel> Query(CatCommodityCriteria criteria)
        {
            Expression <Func <CatCommodityModel, bool> > query = null;

            var commodities = Get();

            if (commodities == null)
            {
                return(null);
            }
            var catCommonityGroups = catCommodityGroupService.Get();
            IQueryable <CatCommodityModel> results = from com in commodities
                                                     join grCom in catCommonityGroups on com.CommodityGroupId equals grCom.Id into grpComs
                                                     from grp in grpComs.DefaultIfEmpty()
                                                     select new CatCommodityModel
            {
                Id                   = com.Id,
                Code                 = com.Code,
                CommodityNameVn      = com.CommodityNameVn,
                CommodityNameEn      = com.CommodityNameEn,
                CommodityGroupId     = com.CommodityGroupId,
                Note                 = com.Note,
                UserCreated          = com.UserCreated,
                DatetimeCreated      = com.DatetimeCreated,
                UserModified         = com.UserModified,
                DatetimeModified     = com.DatetimeModified,
                Active               = com.Active,
                InactiveOn           = com.InactiveOn,
                CommodityGroupNameEn = grp != null ? grp.GroupNameEn : string.Empty,
                CommodityGroupNameVn = grp != null ? grp.GroupNameVn : string.Empty
            };

            if (criteria.All == null)
            {
                query = x => (x.CommodityNameVn ?? "").IndexOf(criteria.CommodityNameVn ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                        (x.CommodityNameEn ?? "").IndexOf(criteria.CommodityNameEn ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                        (x.CommodityGroupNameEn ?? "").IndexOf(criteria.CommodityGroupNameEn ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                        (x.CommodityGroupNameVn ?? "").IndexOf(criteria.CommodityGroupNameVn ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                        (x.Code ?? "").IndexOf(criteria.Code ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                        (x.Active == criteria.Active || criteria.Active == null);
            }
            else
            {
                query = x => ((x.CommodityNameVn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 ||
                              (x.CommodityNameEn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 ||
                              (x.CommodityGroupNameEn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 ||
                              (x.CommodityGroupNameVn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 ||
                              (x.Code ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) &&
                        (x.Active == criteria.Active || criteria.Active == null);
            }
            if (results == null)
            {
                return(null);
            }
            results = results.Where(query);
            return(results);
        }