public Result PostSmartDeviceModel([FromBody] IEnumerable <SmartDeviceModel> deviceModels)
        {
            if (deviceModels == null || !deviceModels.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (deviceModels.Any(x => x.Model.IsNullOrEmpty()))
            {
                return(Result.GenError <Result>(Error.SmartDeviceModelNotEmpty));
            }
            if (deviceModels.GroupBy(x => x.Model).Any(y => y.Count() > 1))
            {
                return(Result.GenError <Result>(Error.SmartDeviceModelDuplicate));
            }
            var cId   = deviceModels.FirstOrDefault()?.CategoryId ?? 0;
            var sames = deviceModels.Select(x => x.Model);

            if (SmartDeviceModelHelper.GetHaveSame(cId, sames))
            {
                return(Result.GenError <Result>(Error.SmartDeviceModelIsExist));
            }
            var userId         = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            foreach (var model in deviceModels)
            {
                model.CreateUserId   = userId;
                model.MarkedDateTime = markedDateTime;
                model.Remark         = model.Remark ?? "";
            }
            SmartDeviceModelHelper.Instance.Add(deviceModels);
            return(Result.GenError <Result>(Error.Success));
        }
        public Result PutSmartDeviceModel([FromBody] IEnumerable <SmartDeviceModel> deviceModels)
        {
            if (deviceModels == null || !deviceModels.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (deviceModels.Any(x => x.Model.IsNullOrEmpty()))
            {
                return(Result.GenError <Result>(Error.SmartDeviceModelNotEmpty));
            }
            if (deviceModels.GroupBy(x => x.Model).Any(y => y.Count() > 1))
            {
                return(Result.GenError <Result>(Error.SmartDeviceModelDuplicate));
            }
            var cId   = deviceModels.FirstOrDefault()?.CategoryId ?? 0;
            var sames = deviceModels.Select(x => x.Model);
            var ids   = deviceModels.Select(x => x.Id);

            if (SmartDeviceModelHelper.GetHaveSame(cId, sames, ids))
            {
                return(Result.GenError <Result>(Error.SmartDeviceModelIsExist));
            }
            var oldModels = SmartDeviceModelHelper.Instance.GetByIds <SmartDeviceModel>(ids);

            if (oldModels.Count() != deviceModels.Count())
            {
                return(Result.GenError <Result>(Error.SmartDeviceModelNotExist));
            }
            var updates        = new List <Tuple <int, int> >();
            var markedDateTime = DateTime.Now;

            foreach (var model in deviceModels)
            {
                model.MarkedDateTime = markedDateTime;
                model.Remark         = model.Remark ?? "";
                var first = oldModels.FirstOrDefault(x => x.Id == model.Id);
                if (first != null && first.CategoryId != model.CategoryId)
                {
                    updates.Add(new Tuple <int, int>(model.Id, model.CategoryId));
                }
            }
            SmartDeviceModelHelper.Instance.Update(deviceModels);
            SmartDeviceHelper.UpdateSmartDeviceCategory(updates);
            return(Result.GenError <Result>(Error.Success));
        }