Exemple #1
0
        public async Task <IActionResult> CreateCategory([FromBody] AddCategoryRequestDto category)
        {
            var verifyResult = VerifyCategory(category);

            if (verifyResult.Code != ErrorCode.Success)
            {
                return(verifyResult);
            }
            ;

            var categoryBiz = new MealCategoryBiz();

            var exsitName = await categoryBiz.ExistCategoryName(category.HospitalGuid, category.CategoryName.Trim());

            if (exsitName)
            {
                return(Failed(ErrorCode.Empty, $"餐别“{category.CategoryName}”已存在"));
            }

            var model = category.ToModel <MealCategoryModel>();

            model.CategoryGuid  = Guid.NewGuid().ToString("N");
            model.CreatedBy     = UserID;
            model.LastUpdatedBy = UserID;
            model.OrgGuid       = "";

            var result = await categoryBiz.CreateCategory(model);

            return(!string.IsNullOrEmpty(result) ? Success()
                : Failed(ErrorCode.DataBaseError, "餐别创建失败!"));
        }
Exemple #2
0
        public async Task <IActionResult> UpdateCategory([FromBody] AddCategoryRequestDto category)
        {
            var verifyResult = VerifyCategory(category);

            if (verifyResult.Code != ErrorCode.Success)
            {
                return(verifyResult);
            }
            ;

            if (string.IsNullOrEmpty(category.CategoryGuid) ||
                string.IsNullOrEmpty(category.HospitalGuid))
            {
                return(Failed(ErrorCode.Empty, "参数不正确"));
            }

            var categoryBiz = new MealCategoryBiz();

            var model = await categoryBiz.GetCategoryModelById(category.HospitalGuid, category.CategoryGuid);

            if (model is null)
            {
                return(Failed(ErrorCode.Empty, $"餐别“{category.CategoryName}”不存在"));
            }

            var exsitName = await categoryBiz.ExistCategoryName(category.HospitalGuid, category.CategoryName.Trim(), category.CategoryGuid);

            if (exsitName)
            {
                return(Failed(ErrorCode.Empty, $"餐别“{category.CategoryName}”已存在,请修改"));
            }

            model.CategoryAdvanceDay   = category.CategoryAdvanceDay;
            model.CategoryName         = category.CategoryName;
            model.CategoryScheduleTime = category.CategoryScheduleTime;
            model.LastUpdatedBy        = UserID;
            model.LastUpdatedDate      = DateTime.Now;
            model.MealStartTime        = category.MealStartTime;
            model.MealEndTime          = category.MealEndTime;

            var result = await categoryBiz.UpdateCategory(model);

            return(result > 0 ? Success() : Failed(ErrorCode.DataBaseError, "餐别更新失败!"));
        }