Example #1
0
        public async Task <BaseResponse> AddSchemaAsync(int typeId, TypeSchemaAddViewModel req, string account)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(typeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            //检查是否存在同名
            var data = await _ts.Find(a => a.TypeId == typeId && a.ParentId == req.ParentId && a.Name == req.Name).FirstOrDefaultAsync();

            if (data != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "已存在相同名称的模式"
                });
            }
            var define = await _td.FindAsync(req.DataDefineId);

            //检查所对应的key值是否存在
            if (define == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的数据定义不存在"
                });
            }
            try
            {
                if (req.ParentId == 0)
                {
                    req.ParentId = null;
                }
                var entity = _mapper.Map <TypeSchemaModel>(req);
                entity.Create = account;
                entity.TypeId = typeId;
                entity.Key    = define.DataKey;
                await _ts.AddAsync(entity);

                _log.LogInformation($"{account}添加模式成功,模式标示为{entity.Id}");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加模式成功", Key = entity.Id
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加模式失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加模式失败,请联系管理员"
                });
            }
        }
        public async Task <BaseResponse> AddTypeHarewareConfigAsync(int typeId, TypeHardwareConfigAddDto req, string account)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(typeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            var dataDefine = await _tdr.FindAsync(req.DataDefineId);

            if (dataDefine == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的数据定义编号不存在"
                });
            }
            var data = await _th.Find(a => a.TypeId == typeId && a.Key == dataDefine.DataKey).FirstOrDefaultAsync();

            if (data != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "该类型下已存在相同的配置数据"
                });
            }
            try
            {
                var entity = _mapper.Map <TypeHardwareConfigModel>(req);
                entity.TypeId  = typeId;
                entity.Create  = account;
                entity.Key     = dataDefine.DataKey;
                entity.KeyName = dataDefine.DataName;
                entity.Unit    = dataDefine.Unit;
                entity.Format  = dataDefine.Format;
                await _th.AddAsync(entity);

                _log.LogInformation($"{account}添加标示为:{entity.Id}的类型PLC配置数据成功");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加配置数据成功", Key = entity.Id
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加类型PLC配置数据失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加类型PLC配置数据失败,请联系管理员"
                });
            }
        }
Example #3
0
        public async Task <BaseResponse> AddStatistics(int typeId, TypeStatisticsAddViewModel req, string account)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(typeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            //验证数据定义是否存在
            var data = await _tdd.FindAsync(req.DataDefineId);

            if (data == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入类型的数据定义不存在"
                });
            }
            //验证统计名称和数据定义key是否存在
            var count = _tsr.Find(a => a.TypeId == typeId && (a.Name == req.Name || a.DataKey == data.DataKey)).Count();

            if (count > 0)
            {
                return(new BaseResponse {
                    Success = false, Message = "此类型下已存在相同名称的统计数据或者相同的key值"
                });
            }
            try
            {
                var entity = _mapper.Map <TypeStatisticsInfoModel>(req);
                entity.TypeId  = typeId;
                entity.Create  = account;
                entity.DataKey = data.DataKey;
                entity.SUnit   = data.Unit;
                await _tsr.AddAsync(entity);

                _log.LogInformation($"{account}添加标示为{entity.Id}的类型统计数据成功");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加类型统计数据成功", Key = entity.Id
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加类型统计数据失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加类型统计数据失败,请联系管理员"
                });
            }
        }
Example #4
0
        public async Task <IActionResult> Recipe(RecipeViewModel model)
        {
            if (model.Ingredients == null)
            {
                ModelState.AddModelError("Ingredients", "Należy dodać chociażby jeden składnik");
            }
            if (!ModelState.IsValid)
            {
                if (ModelState["TypeId"].Errors.Count != 0)
                {
                    ModelState.Remove("TypeId");
                    ModelState.SetModelValue("TypeId", new ValueProviderResult("Należy wybrać typ przepisu", CultureInfo.InvariantCulture));
                    ModelState.AddModelError("TypeId", "Należy wybrać typ przepisu");
                }

                model.Types = await typeRepository.Types();

                return(View("Recipe", model));
            }

            if (model.Image != null)
            {
                if (model.Image.Length > 0)
                {
                    using (var stream = new MemoryStream())
                    {
                        await model.Image.CopyToAsync(stream);

                        model.Recipe.Img = stream.ToArray();
                    }
                }
            }

            IEnumerable <Product> productsToIngredients = await productRepository.FindAllAsync(p => model.Ingredients.Any(i => i.Id == p.Id));

            model.Recipe.Ingredients = new List <Ingredient>();
            foreach (var product in productsToIngredients)
            {
                model.Recipe.Ingredients.Add(new Ingredient {
                    Product = product, Quantity = model.Ingredients.Where(i => i.Id == product.Id).First().Quantity
                });
            }
            model.Recipe.Type = await typeRepository.FindAsync(t => t.Id == model.TypeId);

            recipeRepository.Add(model.Recipe);
            return(RedirectToAction("Recipe"));
        }
Example #5
0
        /// <summary>
        /// 验证该类型下是否能添加相关的信息
        /// </summary>
        /// <param name="Id">类型标示</param>
        /// <param name="GroupId">类型所属的组织编号</param>
        /// <param name="status">类型是否能是叶子节点</param>
        /// <returns>类型是否存在</returns>
        public async Task <TypeCheckDto> CheckTypeAsync(int Id)
        {
            TypeCheckDto dto  = new TypeCheckDto();
            var          data = await _tr.FindAsync(Id);

            if (data == null)
            {
                dto.GroupId = null;
                dto.Status  = 0;
                dto.IsExist = false;
            }
            else
            {
                dto.GroupId = data.GroupId;
                dto.Status  = (int)data.Status;
                dto.IsExist = true;
            }
            return(dto);
        }
Example #6
0
 //调用者检查类型是否存在
 public async Task<BaseResponse> AddTypeDataDefine(int typeId, TypeDataDefineAddViewModel req, string account)
 {
     //验证类型是否可以添加
     var t = await _tr.FindAsync(typeId);
     if (t.Status == TypeStatus.Root)
     {
         return new BaseResponse { Success = false, Message = "目录节点类型不能添加具体数据" };
     }
     var dataDefine = await _ddl.FindAsync(req.DataDefineId);
     if (dataDefine == null)
     {
         return new BaseResponse { Success = false, Message = "输入的数据类型定义标示不存在" };
     }
     //检查是否已存在相同key值
     var ret = await _td.Find(a => a.TypeId == typeId && a.DataKey == dataDefine.DataKey).FirstOrDefaultAsync();
     if (ret != null)
     {
         return new BaseResponse { Success = false, Message = "该类型下存在相同key值" };
     }
     try
     {
         var entity = _mapper.Map<TypeDataDefineModel>(req);
         entity.Create = account;
         entity.TypeId = typeId;
         entity.DataKey = dataDefine.DataKey;
         entity.DataName = dataDefine.DataName;
         entity.Unit = dataDefine.Unit;
         entity.DataType = dataDefine.DataType;
         entity.DefaultValue = dataDefine.DefaultValue;
         entity.Format = dataDefine.Format;
         entity.Model = (DataDefineModel)dataDefine.Model;
         entity.Category = dataDefine.Category;
         await _td.AddAsync(entity);
         _log.LogInformation($"{account}添加类型数据定义{entity.DataKey}成功");
         return new HandleResponse<int> { Success = true, Message = "添加数据成功", Key = entity.Id };
     }
     catch (Exception ex)
     {
         _log.LogError($"{account}添加类型数据定义{dataDefine.DataKey}失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
         return new BaseResponse { Success = false, Message = "添加数据失败,请联系管理员" };
     }
 }
Example #7
0
        public async Task <BaseResponse> AddTypeUpdateFile(int typeId, TypeUpdateFileAddViewModel req, string account, string url)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(typeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            //是否存在重名
            var ret = await _tu.Find(a => a.TypeId == typeId && a.Name == req.Name).FirstOrDefaultAsync();

            if (ret != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "已存在相同名称的升级文件"
                });
            }
            try
            {
                var dto = _mapper.Map <TypeUpdateFileModel>(req);
                dto.Create = account;
                dto.Url    = url;
                dto.TypeId = typeId;
                await _tu.AddAsync(dto);

                _log.LogInformation($"{account}添加Id为{dto.Id}名称为{dto.Name}的升级文件成功");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加升级文件成功", Key = dto.Id
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加升级文件{req.Name}失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加失败文件失败,请联系管理员"
                });
            }
        }
Example #8
0
        public async Task <BaseResponse> AddTypeImage(int typeId, TypeImageAddViewModel req, string account, string path)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(typeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            //验证是否重名
            var ret = await _ti.Find(a => a.TypeId == typeId && a.ImageName == req.ImageName).FirstOrDefaultAsync();

            if (ret != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "该类型下已存在相同名称的图片"
                });
            }
            try
            {
                var dto = _mapper.Map <TypeImageModel>(req);
                dto.TypeId = typeId;
                dto.Url    = path;
                dto.Create = account;
                await _ti.AddAsync(dto);

                _log.LogInformation($"{account}添加类型图片{dto.Id},名称为{dto.ImageName}成功");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加类型图片成功", Key = dto.Id
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加类型图片失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加类型图片失败"
                });
            }
        }
Example #9
0
        /// <summary>
        /// 添加类型分组数据
        /// </summary>
        /// <param name="Account">操作人</param>
        /// <param name="TypeId">类型编号</param>
        /// <param name="req">类型分组数据</param>
        /// <returns></returns>
        public async Task <BaseResponse> AddTypeClassAsync(string Account, int TypeId, TypeClassAddDto req)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(TypeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            //验证是否重名
            var data = await _tcr.Find(a => a.TypeId == TypeId && a.Name == req.Name).FirstOrDefaultAsync();

            if (data != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "已存在相同名称的类型分组,请确认"
                });
            }
            try
            {
                var entity = _mapper.Map <TypeClassModel>(req);
                entity.Create = Account;
                entity.TypeId = TypeId;
                await _tcr.AddAsync(entity);

                _log.LogInformation($"{Account}添加标识为{entity.Id}的类型分组数据成功");
                return(new HandleResponse <int> {
                    Key = entity.Id, Success = true, Message = "添加数据成功"
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{Account}添加类型分组失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加类型分组数据失败,请联系管理员"
                });
            }
        }
Example #10
0
        public async Task <BaseResponse> AddAsync(int typeId, TypeConfigAddViewModel req, string account)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(typeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            //验证是否重名
            var data = await _tc.Find(a => a.TypeId == typeId && a.DataName == req.DataName).FirstOrDefaultAsync();

            if (data != null)
            {
                return(new BaseResponse {
                    Success = true, Message = "已存在相同名称的类型配置,请确认"
                });
            }
            try
            {
                var entity = _mapper.Map <TypeConfigModel>(req);
                entity.Create = account;
                entity.TypeId = typeId;
                await _tc.AddAsync(entity);

                _log.LogInformation($"{account}添加标示为{entity.Id}的类型配置数据成功");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加类型配置数据成功", Key = entity.Id
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加类型配置数据失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加类型配置数据失败,请联系管理员"
                });
            }
        }