Beispiel #1
0
        public Result PostSmartDeviceCategory([FromBody] IEnumerable <SmartDeviceCategory> deviceCategories)
        {
            if (deviceCategories == null || !deviceCategories.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (deviceCategories.Any(x => x.Category.IsNullOrEmpty()))
            {
                return(Result.GenError <Result>(Error.SmartDeviceCategoryNotEmpty));
            }
            if (deviceCategories.GroupBy(x => x.Category).Any(y => y.Count() > 1))
            {
                return(Result.GenError <Result>(Error.SmartDeviceCategoryDuplicate));
            }

            var wId   = deviceCategories.FirstOrDefault()?.WorkshopId ?? 0;
            var sames = deviceCategories.Select(x => x.Category);

            if (SmartDeviceCategoryHelper.GetHaveSame(wId, sames))
            {
                return(Result.GenError <Result>(Error.SmartDeviceCategoryIsExist));
            }

            var userId         = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            foreach (var deviceCategory in deviceCategories)
            {
                deviceCategory.CreateUserId   = userId;
                deviceCategory.MarkedDateTime = markedDateTime;
                deviceCategory.Remark         = deviceCategory.Remark ?? "";
            }
            SmartDeviceCategoryHelper.Instance.Add(deviceCategories);
            return(Result.GenError <Result>(Error.Success));
        }
Beispiel #2
0
        public Result PutSmartDeviceCategory([FromBody] IEnumerable <SmartDeviceCategory> deviceCategories)
        {
            if (deviceCategories == null || !deviceCategories.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (deviceCategories.Any(x => x.Category.IsNullOrEmpty()))
            {
                return(Result.GenError <Result>(Error.SmartDeviceCategoryNotEmpty));
            }
            if (deviceCategories.GroupBy(x => x.Category).Any(y => y.Count() > 1))
            {
                return(Result.GenError <Result>(Error.SmartDeviceCategoryDuplicate));
            }

            var wId   = deviceCategories.FirstOrDefault()?.WorkshopId ?? 0;
            var sames = deviceCategories.Select(x => x.Category);
            var ids   = deviceCategories.Select(x => x.Id);

            if (SmartDeviceCategoryHelper.GetHaveSame(wId, sames, ids))
            {
                return(Result.GenError <Result>(Error.SmartDeviceCategoryIsExist));
            }

            var cnt = SmartDeviceCategoryHelper.Instance.GetCountByIds(ids);

            if (cnt != deviceCategories.Count())
            {
                return(Result.GenError <Result>(Error.SmartDeviceCategoryNotExist));
            }

            var markedDateTime = DateTime.Now;

            foreach (var category in deviceCategories)
            {
                category.MarkedDateTime = markedDateTime;
                category.Remark         = category.Remark ?? "";
            }
            SmartDeviceCategoryHelper.Instance.Update(deviceCategories);
            return(Result.GenError <Result>(Error.Success));
        }