Browse Source

OperationHotelData 增加 Add/Update 验证

leiy 11 months ago
parent
commit
2e80e0f045

+ 8 - 29
OASystem/OASystem.Api/Controllers/ResourceController.cs

@@ -722,36 +722,15 @@ namespace OASystem.API.Controllers
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> OperationHotelData(OperationHotelDto dto)
         {
-            try
-            {
-                if (dto.City == "")
-                {
-                    return Ok(JsonView(false, "请检查酒店所在城市是否填写!"));
-                }
-                if (dto.Name == "")
-                {
-                    return Ok(JsonView(false, "请检查酒店名称是否填写!"));
-                }
-                if (dto.Address == "")
-                {
-                    return Ok(JsonView(false, "请检查酒店地址是否填写正确!"));
-                }
-                if (dto.Tel == "")
-                {
-                    return Ok(JsonView(false, "请检查酒店联系方式是否填写正确!"));
-                }
+            if (string.IsNullOrEmpty(dto.City)) return Ok(JsonView(false, "请检查酒店所在城市是否填写!"));
+            if (string.IsNullOrEmpty(dto.Name)) return Ok(JsonView(false, "请检查酒店名称是否填写!"));
+            if (string.IsNullOrEmpty(dto.Address)) return Ok(JsonView(false, "请检查酒店地址是否填写正确!")); 
+            if (string.IsNullOrEmpty(dto.Tel)) return Ok(JsonView(false, "请检查酒店联系方式是否填写正确!")); 
+
+            Result result = await _hotelDataRep.OperationHotelData(dto);
+            if (result.Code != 0) return Ok(JsonView(false, result.Msg));
+            return Ok(JsonView(true, result.Msg));
 
-                Result result = await _hotelDataRep.OperationHotelData(dto);
-                if (result.Code != 0)
-                {
-                    return Ok(JsonView(false, result.Msg));
-                }
-                return Ok(JsonView(true, result.Msg));
-            }
-            catch (Exception ex)
-            {
-                return Ok(JsonView(false, ex.Message));
-            }
         }
 
         /// <summary>

+ 36 - 42
OASystem/OASystem.Infrastructure/Repositories/Resource/HotelDataRepository.cs

@@ -22,60 +22,54 @@ namespace OASystem.Infrastructure.Repositories.Resource
         public async Task<Result> OperationHotelData(OperationHotelDto dto)
         {
             Result result = new Result() { Code = -2, Msg = "未知错误" };
-            try
+
+            if (dto.Status == 1)//添加
             {
-                if (dto.Status == 1)//添加
+                string selectSql = string.Format(@"select * from Res_HotelData where Name='{0}' and IsDel='{1}'"
+                                                   , dto.Name, 0);
+                var HotelData = await _sqlSugar.SqlQueryable<Res_HotelData>(selectSql).FirstAsync();//查询是否存在
+                if (HotelData != null)
                 {
-                    string selectSql = string.Format(@"select * from Res_HotelData where Name='{0}' and IsDel='{1}'"
-                                                       , dto.Name,0);
-                    var HotelData = await _sqlSugar.SqlQueryable<Res_HotelData>(selectSql).FirstAsync();//查询是否存在
-                    if (HotelData != null)
-                    {
-                        return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
+                    return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
 
-                    }
-                    else//不存在,可添加
-                    {
-                        Res_HotelData _HotelDataDto = _mapper.Map<Res_HotelData>(dto);
-                        int id = await AddAsyncReturnId(_HotelDataDto);
-                        if (id == 0)
-                        {
-                            return result = new Result() { Code = -1, Msg = "添加失败!" };
-
-                        }
-                        return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
-                    }
                 }
-                else if (dto.Status == 2)//修改
+                else//不存在,可添加
                 {
-                    bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_HotelData
+                    Res_HotelData _HotelDataDto = _mapper.Map<Res_HotelData>(dto);
+                    int id = await AddAsyncReturnId(_HotelDataDto);
+                    if (id == 0)
                     {
-                        City = dto.City,
-                        Name = dto.Name,
-                        Level = dto.Level,
-                        Address = dto.Address,
-                        Tel = dto.Tel,
-                        Fax = dto.Fax,
-                        Contact = dto.Contact,
-                        ContactPhone = dto.ContactPhone,
-                        OtherInformation = dto.OtherInformation,
-                        Remark = dto.Remark,
-                    });
-                    if (!res)
-                    {
-                        return result = new Result() { Code = -1, Msg = "修改失败!" };
+                        return result = new Result() { Code = -1, Msg = "添加失败!" };
+
                     }
-                    return result = new Result() { Code = 0, Msg = "修改成功!" };
+                    return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
                 }
-                else
+            }
+            else if (dto.Status == 2)//修改
+            {
+                bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_HotelData
+                {
+                    City = dto.City,
+                    Name = dto.Name,
+                    Level = dto.Level,
+                    Address = dto.Address,
+                    Tel = dto.Tel,
+                    Fax = dto.Fax,
+                    Contact = dto.Contact,
+                    ContactPhone = dto.ContactPhone,
+                    OtherInformation = dto.OtherInformation,
+                    Remark = dto.Remark,
+                });
+                if (!res)
                 {
-                    return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
+                    return result = new Result() { Code = -1, Msg = "修改失败!" };
                 }
+                return result = new Result() { Code = 0, Msg = "修改成功!" };
             }
-            catch (Exception ex)
+            else
             {
-                return result = new Result() { Code = -2, Msg = ex.Message };
-                }
+                return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
+            }
         }
 
         public async Task<Result> QueryHotelData(QueryHotelDataDto dto)