/// <summary> /// 添加配置 /// </summary> /// <param name="priority"></param> /// <param name="name"></param> /// <returns></returns> public bool AddBatteryFastDeliveryPriority(BatteryFastDeliveryPriority priority, string user) { var success = false; try { priority.PKID = dbScopeManagerGungnir.Execute(conn => DalBatteryFastDelivery.AddBatteryFastDeliveryPriority(conn, priority)); success = priority.PKID > 0; if (success) { RecordOperationLog(new BaoYangOprLog { IdentityID = priority.PKID.ToString(), LogType = "BatteryFastDeliveryPriority", NewValue = JsonConvert.SerializeObject(priority), OldValue = string.Empty, OperateUser = user, Remarks = "add", }); } } catch (Exception ex) { Logger.Error(nameof(AddBatteryFastDeliveryPriority), ex); } return(success); }
public bool IsExistsBatteryFastDeliveryPriority(BatteryFastDeliveryPriority priority) { var result = true; try { result = dbScopeManagerGungnirRead.Execute(conn => DalBatteryFastDelivery.IsExistsBatteryFastDeliveryPriority(conn, priority)); } catch (Exception ex) { Logger.Error(nameof(IsExistsBatteryFastDeliveryPriority), ex); } return(result); }
/// <summary> /// 根据id获取配置 /// </summary> /// <param name="id"></param> /// <returns></returns> public BatteryFastDeliveryPriority GetBatteryFastDeliveryPriority(int id) { BatteryFastDeliveryPriority result = null; try { result = dbScopeManagerGungnirRead.Execute(conn => DalBatteryFastDelivery.GetBatteryFastDeliveryPriorities(conn, id)); } catch (Exception ex) { Logger.Error(nameof(GetBatteryFastDeliveryPriority), ex); } return(result); }
/// <summary> /// 修改配置 /// </summary> /// <param name="priority"></param> /// <returns></returns> public static bool UpdateBatteryFastDeliveryPriority(SqlConnection conn, BatteryFastDeliveryPriority priority) { const string sql = @"UPDATE t SET t.Priorities = @Priorities , t.LastUpdateDateTime = GETDATE() , t.IsEnabled = @IsEnabled FROM BaoYang..BatteryFastDeliveryPriority AS t WHERE t.PKID = @PKID;"; var parameters = new[] { new SqlParameter("@PKID", priority.PKID), new SqlParameter("@Priorities", string.Join(";", priority.Priorities ?? new List <string>())), new SqlParameter("@IsEnabled", priority.IsEnabled), }; var rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, parameters); return(rows > 0); }
/// <summary> /// 是否存在 /// </summary> /// <param name="priority"></param> /// <returns></returns> public static bool IsExistsBatteryFastDeliveryPriority(SqlConnection conn, BatteryFastDeliveryPriority priority) { const string sql = @"SELECT COUNT(t.PKID) FROM BaoYang..BatteryFastDeliveryPriority AS t WITH ( NOLOCK ) WHERE t.PKID <> @PKID AND t.ProvinceId = @ProvinceId AND t.CityId = @CityId;"; var parameters = new[] { new SqlParameter("@PKID", priority.PKID), new SqlParameter("@ProvinceId", priority.ProvinceId), new SqlParameter("@ProvinceName", priority.ProvinceName), new SqlParameter("@CityId", priority.CityId), new SqlParameter("@CityName", priority.CityName), }; var countObj = SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters); var count = Convert.ToInt32(countObj); return(count > 0); }
/// <summary> /// 添加或者修改服务类蓄电池产品优先级 /// </summary> /// <returns></returns> public ActionResult AddOrUpdateBatteryFastDeliveryPriority(BatteryFastDeliveryPriority priority) { var manager = new BatteryFastDeliveryConfigManager(); Func <string> validFunc = () => { if (priority == null) { return("参数不能为空"); } if (priority.ProvinceId < 0 || string.IsNullOrWhiteSpace(priority.ProvinceName) || priority.CityId < 0 || string.IsNullOrWhiteSpace(priority.CityName)) { return("地区不能为空"); } if (priority.Priorities == null || !priority.Priorities.Any()) { return("至少选择一个优先级"); } if (manager.IsExistsBatteryFastDeliveryPriority(priority)) { return("数据已经存在"); } return(string.Empty); }; var validResult = validFunc(); if (!string.IsNullOrEmpty(validResult)) { return(Json(new { status = false, msg = validResult })); } var result = priority.PKID > 0 ? manager.UpdateBatteryFastDeliveryPriority(priority, User.Identity.Name) : manager.AddBatteryFastDeliveryPriority(priority, User.Identity.Name); return(Json(new { status = result })); }
/// <summary> /// 修改配置 /// </summary> /// <param name="priority"></param> /// <param name="name"></param> /// <returns></returns> public bool UpdateBatteryFastDeliveryPriority(BatteryFastDeliveryPriority priority, string user) { var success = false; try { var origin = GetBatteryFastDeliveryPriority(priority.PKID); if (origin != null) { priority.CityId = origin.CityId; priority.CityName = origin.CityName; priority.ProvinceId = origin.ProvinceId; priority.ProvinceName = origin.ProvinceName; priority.CreateDateTime = origin.CreateDateTime; success = dbScopeManagerGungnir.Execute(conn => DalBatteryFastDelivery.UpdateBatteryFastDeliveryPriority(conn, priority)); priority.LastUpdateDateTime = DateTime.Now; } if (success) { RecordOperationLog(new BaoYangOprLog { IdentityID = priority.PKID.ToString(), LogType = "BatteryFastDeliveryPriority", NewValue = JsonConvert.SerializeObject(priority), OldValue = JsonConvert.SerializeObject(origin), OperateUser = user, Remarks = "update", }); } } catch (Exception ex) { Logger.Error(nameof(UpdateBatteryFastDeliveryPriority), ex); } return(success); }
/// <summary> /// 添加配置 /// </summary> /// <param name="priority"></param> /// <returns></returns> public static int AddBatteryFastDeliveryPriority(SqlConnection conn, BatteryFastDeliveryPriority priority) { const string sql = @"INSERT INTO BaoYang..BatteryFastDeliveryPriority ( ProvinceId , ProvinceName , CityId , CityName , Priorities , IsEnabled , CreateDateTime , LastUpdateDateTime ) OUTPUT Inserted.PKID VALUES ( @ProvinceId , @ProvinceName , @CityId , @CityName , @Priorities , @IsEnabled , GETDATE() , GETDATE() );"; var parameters = new[] { new SqlParameter("@Priorities", string.Join(";", priority.Priorities ?? new List <string>())), new SqlParameter("@IsEnabled", priority.IsEnabled), new SqlParameter("@ProvinceId", priority.ProvinceId), new SqlParameter("@ProvinceName", priority.ProvinceName), new SqlParameter("@CityId", priority.CityId), new SqlParameter("@CityName", priority.CityName), }; var result = SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters); var pkid = Convert.ToInt32(result); return(pkid); }