/// <summary> /// 删除文件记录及物理文件 /// </summary> /// <param name="filepath"></param> /// <param name="dbContext"></param> /// <returns></returns> public static async Task <bool> DelFile(string Code, ContextString dbContext) { bool _Result = false; try { var file = await dbContext.AssetFiles.Where(i => i.Code == Code).AsNoTracking().FirstOrDefaultAsync(); var path = Method._hostingEnvironment.WebRootPath + file.FilePath; DirectoryInfo info = new DirectoryInfo(path); Directory.Delete(info.Parent.FullName, true); dbContext.AssetFiles.Remove(file); if (await dbContext.SaveChangesAsync() > 0) { _Result = true; } } catch (Exception e) { QMLog qm = new QMLog(); qm.WriteLogToFile("删除文件出错", e.ToString()); } return(_Result); }
/// <summary> /// 创建一个用户 /// </summary> /// <param name="dbContext"></param> /// <param name="_Account"></param> /// <returns></returns> public async static Task <int> CreateAccount(ContextString dbContext, Account _Account) { dbContext.Account.Add(_Account); await dbContext.SaveChangesAsync(); return(_Account.ID); }
public async Task <IActionResult> CancelPublish(Input_SubtitlePublishCancel model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); try { Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_SubtitlePublishCancel)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (model.Code.Count() <= 0) { _Result.Code = "510"; _Result.Msg = "编码不可为空"; _Result.Data = ""; return(Json(_Result)); } foreach (var c in model.Code) { var std = await dbContext.SubtitleToDeviceGroup.Where(i => !i.IsDel && i.Code == c).FirstOrDefaultAsync(); if (std != null) { std.IsDel = true; std.UpdateTime = DateTime.Now; dbContext.SubtitleToDeviceGroup.Update(std); } else { _Result.Code = "510"; _Result.Msg = "无效的关联编码:" + c; _Result.Data = ""; return(Json(_Result)); } } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "取消成功"; _Result.Data = ""; } } catch (Exception e) { _Result.Code = "500"; _Result.Msg = "代码错误"; _Result.Data = e.ToString(); throw; } return(Json(_Result)); }
public async Task <IActionResult> SetTimeRelate(Input_TimeRelate model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); //检测用户登录情况 Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_TimeRelate)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); foreach (var item in model.TimeRelateList) { var timeRelate = await dbContext.TimeRelate.Where(t => t.Code == item.TimeRelateCode).FirstOrDefaultAsync(); if (timeRelate != null) { timeRelate.OpenTime = item.OpenTime; timeRelate.UpdateTime = DateTime.Now; dbContext.TimeRelate.Update(timeRelate); } } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "设置成功"; _Result.Data = ""; } else { _Result.Code = "501"; _Result.Msg = "设置失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> PublishProgramToDevice(Input_ProgramToDevice model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); //检测用户登录情况 //string username = Method.GetLoginUserName(dbContext, this.HttpContext); //if (string.IsNullOrEmpty(username)) //{ // _Result.Code = "401"; // _Result.Msg = "请登陆后再进行操作"; // _Result.Data = ""; // return Json(_Result); //} Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_ProgramToDevice)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); //检测用户输入格式 if (!ModelState.IsValid) { _Result.Code = "510"; _Result.Msg = "请求信息不正确"; _Result.Data = ""; return(Json(_Result)); } if (string.IsNullOrEmpty(model.GName)) { _Result.Code = "510"; _Result.Msg = "名称不可为空"; _Result.Data = ""; return(Json(_Result)); } //判断屏幕类型是否有效 int sCount = dbContext.ScreenInfo.Where(i => i.Code == model.ScreenInfoCode).Count(); if (sCount <= 0) { _Result.Code = "510"; _Result.Msg = "未知的屏幕类型"; _Result.Data = ""; return(Json(_Result)); } //判断设备组是否已存在 int count = dbContext.DeviceGroup.Where(i => i.GName == model.GName).Count(); if (count > 0) { _Result.Code = "1"; _Result.Msg = "设备组已存在"; _Result.Data = ""; return(Json(_Result)); } //检查组中的设备 if (model.Devices.Count() > 0) { var errorNoCodeList = new ArrayList(); var errorScreenList = new ArrayList(); var errorSyncList = new ArrayList(); var errorExistList = new ArrayList(); //判断ID是否都为有效设备 foreach (var item in model.Devices) { var dev = await dbContext.Device.Where(i => i.Code == item).FirstOrDefaultAsync(); if (dev == null) { errorNoCodeList.Add(item); } if (dev.ScreenInfo.ToLower() != model.ScreenInfoCode.ToLower()) { errorScreenList.Add(dev.IP); } if (dev.IsSyn != model.IsSync) { errorSyncList.Add(dev.DevNum); } if (model.IsSync) { var dgnum = await dbContext.DeviceToGroup.Where(i => i.DeviceCode == item).CountAsync(); if (dgnum > 0) { errorExistList.Add(dev.DevNum); } } else { var dgnum = await dbContext.DeviceToGroup.Where(i => i.DeviceCode == item).Join(dbContext.DeviceGroup.Where(i => i.Type == 2), d => d.GroupCode, g => g.Code, (d, g) => d).CountAsync(); if (dgnum > 0) { errorExistList.Add(dev.DevNum); } } } if (errorNoCodeList.Count > 0) { _Result.Code = "510"; _Result.Msg = "没有编码为:" + string.Join(";", (string[])errorNoCodeList.ToArray(typeof(string))) + "的设备"; _Result.Data = ""; return(Json(_Result)); } if (errorScreenList.Count > 0) { _Result.Code = "510"; _Result.Msg = "IP为:" + string.Join(";", (string[])errorScreenList.ToArray(typeof(string))) + "的设备屏幕分辨率与设备组分辨率不一致"; _Result.Data = ""; return(Json(_Result)); } if (errorSyncList.Count > 0) { _Result.Code = "510"; _Result.Msg = "设备名:" + string.Join(";", (string[])errorSyncList.ToArray(typeof(string))) + "的设备同步属性与设备组属性不一致"; _Result.Data = ""; return(Json(_Result)); } if (errorExistList.Count > 0) { _Result.Code = "510"; if (model.IsSync) { _Result.Msg = "设备名为:" + string.Join(";", (string[])errorExistList.ToArray(typeof(string))) + "的设备已存在于其他设备组"; } else { _Result.Msg = "设备名为:" + string.Join(";", (string[])errorExistList.ToArray(typeof(string))) + "的设备已存在于其他同步设备组"; } _Result.Data = ""; return(Json(_Result)); } } //添加设备组 DeviceGroup _DG = new DeviceGroup(); _DG.AddTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); _DG.ScreenInfoCode = model.ScreenInfoCode; _DG.GName = model.GName; _DG.Code = Guid.NewGuid().ToString(); _DG.UpdateTime = DateTime.Now; _DG.Type = model.IsSync ? 2 : 1; dbContext.DeviceGroup.Add(_DG); if (await dbContext.SaveChangesAsync() > 0) { //var count=dbContext.ProgramDevice.Where(i=>i.) ProgramDevice _PD = new ProgramDevice(); _PD.Code = Guid.NewGuid().ToString(); _PD.AddTime = DateTime.Now; _PD.DeviceGrounpCode = _DG.Code; _PD.ProgramGrounpCode = model.ProgramGroupCode; _PD.UpdateTime = DateTime.Now; dbContext.ProgramDevice.Add(_PD); //添加设备到设备组 if (model.Devices.Count > 0) { foreach (var item in model.Devices) { dbContext.DeviceToGroup.Add(new DeviceToGroup { AddTime = DateTime.Now, DeviceCode = item, GroupCode = _DG.Code, Code = Guid.NewGuid().ToString(), UpdateTime = DateTime.Now }); } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "添加成功"; _Result.Data = ""; //var _thisjobId = BackgroundJob.Schedule(() => SynData.SendDevInfo(), TimeSpan.FromSeconds(1)); //var ip = Method.GetUserIp(this.HttpContext); //dbContext.SysLog.Add(new SysLog { AccountName = username, ModuleName = "设备组模块", LogMsg = username + "添加了设备组:" + model.GName, AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "创建", IP = ip }); // dbContext.SaveChanges(); } else { _Result.Code = "4"; _Result.Msg = "添加设备到设备组组失败"; _Result.Data = ""; } } else { _Result.Code = "200"; _Result.Msg = "添加成功"; _Result.Data = ""; // var _thisjobId = BackgroundJob.Schedule(() => SynData.SendDevInfo(), TimeSpan.FromSeconds(1)); } } else { _Result.Code = "5"; _Result.Msg = "添加设备组失败"; _Result.Data = ""; } return(Json(_Result)); }
/// <summary> /// 设备心跳包 /// </summary> /// <param name="ip"></param> /// <param name="dbContext"></param> /// <returns></returns> public async Task <IActionResult> DeviceHeartbeat(Input_Heartbeat model, [FromServices] ContextString dbContext) { try { QianMuResult _Result = new QianMuResult(); //检测用户输入格式 if (String.IsNullOrEmpty(model.Code)) { _Result.Code = "510"; _Result.Msg = "编码不可为空"; _Result.Data = ""; return(Json(_Result)); } DateTime dtime = DateTime.Now; //数据库操作 List <Output_DeviceHeartbeat> heart = new List <Output_DeviceHeartbeat>(); //判断设备是否存在 var d = await dbContext.Device.Where(i => i.Code == model.Code).FirstOrDefaultAsync(); if (d != null) { #region 向云端发生心跳 var deviceiot = await dbContext.DeviceIOT.Where(i => i.DeviceCode == d.Code).FirstOrDefaultAsync(); MqttClient mqttClient = new MqttClient(Method.BaiduIOT, 1883, deviceiot.DeviceCode.Replace("-", ""), deviceiot.Name, deviceiot.Key); var redata = new { AppName = model.AppName, AppNameCH = model.AppVersion, AppVersion = model.AppVersion, ContainerVersion = model.ContainerVersion }; var restr = JsonHelper.SerializeJSON(redata); await mqttClient.PublishAsync(deviceiot.DeviceCode.Replace("-", ""), restr); #endregion var dadcount = await dbContext.DevAppDetails.Where(i => i.DevCode == d.Code).AsNoTracking().CountAsync(); var daocount = await dbContext.DevAppOnline.Where(i => i.DeviceCode == d.Code).AsNoTracking().CountAsync(); string appname = model.AppName == null ? "" : model.AppName.ToLower(); string appnamecn = model.AppNameCH == null ? "" : model.AppNameCH.ToLower(); var app = await dbContext.Application.Where(i => i.NameEn.ToLower() == appname && !string.IsNullOrEmpty(i.NameEn)).AsNoTracking().FirstOrDefaultAsync(); var appid = app == null ? "" : app.AppID; if (daocount <= 0) { DevAppOnline dao = new DevAppOnline(); dao.AddTime = DateTime.Now; dao.AppName = string.IsNullOrEmpty(appnamecn) ? appname : appnamecn; dao.AppVersion = model.AppVersion == null ? "" : model.AppVersion.Replace('\u0000', ' ').Trim(); dao.ContainerVersion = model.ContainerVersion == null ? "" : model.ContainerVersion.Replace('\u0000', ' ').Trim(); dao.Code = Guid.NewGuid().ToString(); dao.UpdateTime = DateTime.Now; dao.DeviceCode = d.Code; dbContext.DevAppOnline.Add(dao); await dbContext.SaveChangesAsync(); } else { var dao = await dbContext.DevAppOnline.Where(i => i.DeviceCode == d.Code).FirstOrDefaultAsync(); dao.UpdateTime = DateTime.Now; dao.AppName = string.IsNullOrEmpty(appnamecn) ? appname : appnamecn; dao.AppVersion = model.AppVersion == null ? "" : model.AppVersion.Replace('\u0000', ' ').Trim(); dao.ContainerVersion = model.ContainerVersion == null ? "" : model.ContainerVersion.Replace('\u0000', ' ').Trim(); dbContext.DevAppOnline.UpdateRange(dao); await dbContext.SaveChangesAsync(); } bool isComplete = !string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(model.AppVersion);//true 完整 false 不完整 if (dadcount <= 0) { //尚无记录 容器版本或程序信息是有的 添加一条记录 if (!string.IsNullOrEmpty(model.ContainerVersion) || isComplete) { DevAppDetails dad = new DevAppDetails { AddTime = DateTime.Now, AppID = appid, AppVersion = model.AppVersion == null ? "" : model.AppVersion, Code = Guid.NewGuid().ToString(), ContainerVersion = model.ContainerVersion, DevCode = d.Code }; dbContext.DevAppDetails.Add(dad); await dbContext.SaveChangesAsync(); } } else { //已有记录 if (!string.IsNullOrEmpty(model.ContainerVersion)) { var dads = await dbContext.DevAppDetails.Where(i => i.DevCode == d.Code).ToListAsync(); foreach (var item in dads) { item.ContainerVersion = model.ContainerVersion; } dbContext.DevAppDetails.UpdateRange(dads); await dbContext.SaveChangesAsync(); } if (isComplete) { var dad = await dbContext.DevAppDetails.Where(i => i.DevCode == d.Code && i.AppID == appid).FirstOrDefaultAsync(); if (dad == null) { DevAppDetails devappdetial = new DevAppDetails { AddTime = DateTime.Now, AppID = appid, AppVersion = model.AppVersion, Code = Guid.NewGuid().ToString(), ContainerVersion = model.ContainerVersion, DevCode = d.Code }; dbContext.DevAppDetails.Add(devappdetial); await dbContext.SaveChangesAsync(); } else { dad.AppVersion = model.AppVersion; dbContext.DevAppDetails.Update(dad); await dbContext.SaveChangesAsync(); } } } //初始化心跳包 heart.Add(new Output_DeviceHeartbeat { Type = "downTime", Parameter = d.ShutdownTime }); //判断是否有对应设备存在 var l = Method.DeviceCommandList.Where(i => i.Code == d.Code).FirstOrDefault(); if (l == null) { var abtime = Convert.ToDateTime("2000-01-01"); if (!String.IsNullOrEmpty(model.AppName) || !String.IsNullOrEmpty(model.AppNameCH)) { abtime = dtime; } //添加设备 Method.DeviceCommandList.Add(new DeviceCommand { Code = d.Code, DevBreathTime = dtime, AppBreathTime = abtime, Type = "" }); } else { l.DevBreathTime = dtime; if (!String.IsNullOrEmpty(model.AppName) || !String.IsNullOrEmpty(model.AppNameCH)) { l.AppBreathTime = dtime; } } var tslist = await dbContext.TimeSlot.ToListAsync(); var tscode = ""; foreach (var ts in tslist) { var btime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + ts.BeginTimeSlot + ":00"); var etime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + ts.EndTimeSlot + ":00"); if (DateTime.Now >= btime && DateTime.Now < etime) { tscode = ts.Code; break; } } var appdev = await dbContext.AppTime.Where(i => i.TimeSlot == tscode).Join(dbContext.AppDev.Where(i => i.DevCode == d.Code), at => at.AppCode, ad => ad.Code, (at, ad) => new { ad.AppCode }).Join(dbContext.ApplicationNew, ap => ap.AppCode, an => an.Code, (ap, an) => new { an.Name }).FirstOrDefaultAsync(); if (appdev == null) { var defaultapp = await dbContext.AppDev.Where(i => i.DevCode == d.Code && i.Default).Join(dbContext.ApplicationNew, ad => ad.AppCode, an => an.Code, (ad, an) => new { an.Name }).FirstOrDefaultAsync(); if (defaultapp != null) { heart.Add(new Output_DeviceHeartbeat { Parameter = defaultapp.Name, Type = "AppName" }); } } else { heart.Add(new Output_DeviceHeartbeat { Parameter = appdev.Name, Type = "AppName" }); } _Result.Code = "200"; _Result.Msg = ""; _Result.Data = heart; return(Json(_Result)); } else { _Result.Code = "1"; _Result.Msg = "无效的IP,找不到对应机器"; _Result.Data = ""; return(Json(_Result)); } } catch (Exception e) { QMLog qMLog = new QMLog(); qMLog.WriteLogToFile("DeviceHeartbeat", e.ToString()); throw; } }
public async Task <IActionResult> Add(Input_Prog model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_Prog)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); UserOnLine uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (uol == null || string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } String MallCode = model.MallCode; if (string.IsNullOrEmpty(MallCode)) { MallCode = uol.MallCode; } try { //检测用户登录情况 //string username = Method.GetLoginUserName(dbContext, this.HttpContext); //if (string.IsNullOrEmpty(username)) //{ // _Result.Code = "401"; // _Result.Msg = "请登陆后再进行操作"; // _Result.Data = ""; // return Json(_Result); //} var mall = await dbContext.Mall.Where(i => i.Code == MallCode).FirstOrDefaultAsync(); if (mall == null) { _Result.Code = "510"; _Result.Msg = "无效的商场编码"; _Result.Data = ""; return(Json(_Result)); } var LaunchTime = Convert.ToDateTime(model.LaunchTime); var ExpiryDate = Convert.ToDateTime(model.ExpiryDate); var scount = await dbContext.ScreenInfo.Where(i => i.Code == model.ScreenInfo).CountAsync(); if (scount <= 0) { _Result.Code = "510"; _Result.Msg = "无效的屏幕类型"; _Result.Data = ""; return(Json(_Result)); } if (model.ProgFiles.Count() <= 0) { _Result.Code = "510"; _Result.Msg = "素材数量不应为空"; _Result.Data = ""; return(Json(_Result)); } foreach (var pf in model.ProgFiles) { Programs p = new Programs(); if (string.IsNullOrEmpty(pf.ProgramName)) { _Result.Code = "510"; _Result.Msg = "节目名称不可为空"; _Result.Data = ""; return(Json(_Result)); } var file = await dbContext.AssetFiles.Where(i => i.Code == pf.Code).FirstOrDefaultAsync(); if (file == null) { _Result.Code = "510"; _Result.Msg = "无效的素材编码:" + pf.Code; _Result.Data = ""; return(Json(_Result)); } if (string.IsNullOrEmpty(pf.PreviewFileGUID)) { pf.PreviewFileGUID = pf.Code; p.PreviewSrc = file.FilePath; } else { var pfile = await dbContext.AssetFiles.Where(i => i.Code == pf.PreviewFileGUID).FirstOrDefaultAsync(); if (pfile == null) { _Result.Code = "510"; _Result.Msg = "无效的素材编码:" + pf.PreviewFileGUID; _Result.Data = ""; return(Json(_Result)); } p.PreviewSrc = pfile.FilePath; } p.MallCode = MallCode; p.ExpiryDate = ExpiryDate; p.LaunchTime = LaunchTime; p.ProgScreenInfo = model.ScreenInfo; p.ScreenMatch = model.ScreenMatch; p.SwitchMode = model.SwitchMode; p.SwitchTime = model.SwitchTime; p.ProgramName = pf.ProgramName; p.AddTime = DateTime.Now; p.ProgSrc = file.FilePath; p.ProgType = file.FileType; p.Code = Guid.NewGuid().ToString(); p.UpdateTime = DateTime.Now; p.Code = pf.Code; p.PreviewFileGuid = pf.PreviewFileGUID; dbContext.Programs.Add(p); } if (await dbContext.SaveChangesAsync() >= 0) { _Result.Code = "200"; _Result.Msg = "添加成功"; _Result.Data = ""; } } catch (Exception e) { _Result.Code = "500"; _Result.Msg = "Erro: " + e.ToString(); _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> Add(Input_BuildingAdd model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_BuildingAdd)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (String.IsNullOrEmpty(model.BuildingName)) { _Result.Code = "510"; _Result.Msg = "请输入楼栋名称"; _Result.Data = ""; return(Json(_Result)); } if (string.IsNullOrEmpty(model.MallCode)) { //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { model.MallCode = uol.MallCode; } } var Buildingcount = await dbContext.MallBuilding.Where(i => i.MallCode == model.MallCode).Join(dbContext.Building.Where(i => i.Name.ToLower() == model.BuildingName.ToLower() && !i.IsDel), ma => ma.BuildingCode, ai => ai.Code, (ma, ai) => new { ai.Name }).CountAsync(); //var Building = await dbContext.BuildingInfo.Where(i => i.BuildingName == model.BuildingName).CountAsync(); if (Buildingcount > 0) { _Result.Code = "510"; _Result.Msg = "楼栋名称已存在"; _Result.Data = ""; return(Json(_Result)); } int order = 0; var nowcount = await dbContext.MallBuilding.Where(i => i.MallCode == model.MallCode).Join(dbContext.Building.Where(i => !i.IsDel), ma => ma.BuildingCode, ai => ai.Code, (ma, ai) => new { ai.Name }).CountAsync(); if (nowcount <= 0) { order = 0; } else { //order = dbContext.BuildingInfo.Max(m => m.Order) + 1; order = dbContext.MallBuilding.Where(i => i.MallCode == model.MallCode).Join(dbContext.Building.Where(i => !i.IsDel), ma => ma.BuildingCode, ai => ai.Code, (ma, ai) => new { ai.Name, ai.Order }).Max(m => m.Order) + 1; } Building BuildingInfo = new Building { AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), UpdateTime = DateTime.Now, Name = model.BuildingName, NameEn = string.Empty, Order = order }; dbContext.Building.Add(BuildingInfo); dbContext.MallBuilding.Add(new MallBuilding { AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), UpdateTime = DateTime.Now, BuildingCode = BuildingInfo.Code, MallCode = model.MallCode }); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "添加成功"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> Edit(Input_EditRole model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_EditRole)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); //检测用户登录情况 UserOnLine userOnLine = Method.GetLoginUserName(dbContext, this.HttpContext); if (userOnLine == null || string.IsNullOrEmpty(userOnLine.UserCode)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } if (string.IsNullOrEmpty(model.Name)) { _Result.Code = "510"; _Result.Msg = "角色名称不可为空"; _Result.Data = ""; return(Json(_Result)); } Regex regExp = new Regex("[ \\[ \\] \\^ \\-_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]"); if (regExp.IsMatch(model.Name)) { _Result.Code = "510"; _Result.Msg = "角色名称不能有特殊字符"; _Result.Data = ""; return(Json(_Result)); } var count = await dbContext.Roles.Where(i => i.Code == model.Code).AsNoTracking().CountAsync(); if (count <= 0) { _Result.Code = "510"; _Result.Msg = "角色不存在"; _Result.Data = ""; return(Json(_Result)); } //更新角色 if (regExp.IsMatch(model.Intro)) { _Result.Code = "510"; _Result.Msg = "角色描述不能有特殊字符"; _Result.Data = ""; return(Json(_Result)); } var role = await dbContext.Roles.Where(i => i.Code == model.Code).FirstOrDefaultAsync(); if (role.Name == "超级管理员") { _Result.Code = "510"; _Result.Msg = "超级管理员不可修改"; _Result.Data = ""; return(Json(_Result)); } role.Description = model.Name; role.Name = model.Name; role.Intro = model.Intro; dbContext.Roles.UpdateRange(role); dbContext.RolePermissions.RemoveRange(dbContext.RolePermissions.Where(i => i.RoleCode == model.Code)); //如果有设备控制权限 则加上设备查看权限 var _DeviceControl = await dbContext.Permission.Where(i => i.Description == "DeviceControl").FirstOrDefaultAsync(); var _DevListMgr = await dbContext.Permission.Where(i => i.Description == "DevListMgr").FirstOrDefaultAsync(); if (model.PermissionCode.Contains(_DeviceControl.Code)) { if (!model.PermissionCode.Contains(_DevListMgr.Code)) { model.PermissionCode.Add(_DevListMgr.Code); } } List <RolePermissions> list = new List <RolePermissions>(); foreach (var p in model.PermissionCode) { var percount = await dbContext.Permission.Where(i => i.Code == p).CountAsync(); if (percount <= 0) { _Result.Code = "510"; _Result.Msg = "无效的权限编码:" + p; _Result.Data = ""; return(Json(_Result)); } var per = await dbContext.Permission.Where(i => i.Code == p).FirstOrDefaultAsync(); var parents = await dbContext.Permission.Where(i => i.Code == per.ParentCode).FirstOrDefaultAsync(); list.Add(new RolePermissions { AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), PermissionCode = p, RoleCode = role.Code }); if (list.Where(i => i.PermissionCode == parents.Code).Count() <= 0) { list.Add(new RolePermissions { AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), PermissionCode = parents.Code, RoleCode = role.Code }); } // dbContext.RolePermissions.Add(new RolePermissions { AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), PermissionCode = p, RoleCode = role.Code }); } list = list.Distinct().ToList(); dbContext.RolePermissions.AddRange(list); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "修改成功"; _Result.Data = ""; var ip = Method.GetUserIp(this.HttpContext); dbContext.SysLog.Add(new SysLog { AccountName = userOnLine.UserName, ModuleName = "用户模块", LogMsg = userOnLine.UserName + "修改角色:" + model.Name, AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "修改", IP = ip, MallCode = userOnLine.MallCode, SystemModule = "Mall" }); dbContext.SaveChanges(); } else { _Result.Code = "1"; _Result.Msg = "修改失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> FloorEdit(Input_FloorEdit model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_FloorEdit)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (string.IsNullOrEmpty(model.UserName)) { //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { model.UserName = uol.UserName; } } //if (string.IsNullOrEmpty(model.Code) || string.IsNullOrEmpty(model.Code)) if (string.IsNullOrEmpty(model.Code)) { _Result.Code = "510"; _Result.Msg = "请输入一个楼层编码"; _Result.Data = ""; return(Json(_Result)); } if (string.IsNullOrEmpty(model.Name)) { _Result.Code = "510"; _Result.Msg = "楼层名称不可为空"; _Result.Data = ""; return(Json(_Result)); } var floor = await dbContext.Floor.Where(i => i.Code == model.Code && !i.IsDel).FirstOrDefaultAsync(); if (floor == null) { _Result.Code = "510"; _Result.Msg = "楼层不存在"; _Result.Data = ""; return(Json(_Result)); } if (!string.IsNullOrEmpty(model.Code)) { var file = await dbContext.AssetFiles.Where(i => i.Code == model.Code).FirstOrDefaultAsync(); if (file == null) { _Result.Code = "510"; _Result.Msg = "无效的文件ID"; _Result.Data = ""; return(Json(_Result)); } FileTypeJudgment fimg = new FileTypeJudgment() { TypeTarget = new TypeImg() }; if (!fimg.Judge(file.FileExtName)) { _Result.Code = "510"; _Result.Msg = "地图文件不是图片"; _Result.Data = ""; return(Json(_Result)); } floor.Map = model.Code; } floor.Name = model.Name; floor.UpdateTime = DateTime.Now; dbContext.Floor.Update(floor); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "修改成功"; _Result.Data = ""; var ip = Method.GetUserIp(this.HttpContext); dbContext.SysLog.Add(new SysLog { AccountName = model.UserName, ModuleName = "楼层管理", LogMsg = model.UserName + "修改了名称:" + model.Name + "的楼层地图", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "修改", IP = ip }); dbContext.SaveChanges(); } else { _Result.Code = "1"; _Result.Msg = "修改失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> Unbinding(Input_SUUnbinding model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); ////检测用户登录情况 //var uol = Method.GetLoginUserName(dbContext, this.HttpContext); //if (string.IsNullOrEmpty(uol.UserName)) //{ // _Result.Code = "401"; // _Result.Msg = "请登陆后再进行操作"; // _Result.Data = ""; // return Json(_Result); //} Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_SUUnbinding)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (string.IsNullOrEmpty(model.Code)) { _Result.Code = "510"; _Result.Msg = "请输入绑定用户编码"; _Result.Data = ""; return(Json(_Result)); } var sa = await dbContext.ShopAccount.Where(i => i.Code == model.Code).FirstOrDefaultAsync(); if (sa == null) { _Result.Code = "510"; _Result.Msg = "无效的编码"; _Result.Data = ""; return(Json(_Result)); } var shopnum = await dbContext.ShopNum.Where(i => i.ShopCode == sa.ShopCode).FirstOrDefaultAsync(); shopnum.Num = Method.GetRandomStr(6, dbContext).ToString(); shopnum.UpdateTime = DateTime.Now; dbContext.ShopNum.Update(shopnum); dbContext.ShopAccount.Remove(sa); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "解绑成功"; _Result.Data = ""; } else { _Result.Code = "2"; _Result.Msg = "解绑失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> Publish(Input_SubtitlePublish model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); try { //检测用户登录情况 //string username = Method.GetLoginUserName(dbContext, this.HttpContext); //if (string.IsNullOrEmpty(username)) //{ // _Result.Code = "401"; // _Result.Msg = "请登陆后再进行操作"; // _Result.Data = ""; // return Json(_Result); //} Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_SubtitlePublish)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (string.IsNullOrEmpty(model.Code)) { _Result.Code = "510"; _Result.Msg = "字幕编码不可为空"; _Result.Data = ""; return(Json(_Result)); } var subtitle = await dbContext.Subtitle.Where(i => !i.IsDel && i.Code == model.Code).FirstOrDefaultAsync(); if (subtitle == null) { _Result.Code = "510"; _Result.Msg = "无效的字幕编码:" + model.Code; _Result.Data = ""; return(Json(_Result)); } //获取设备组 到设备关系列表 var deviceGroups = await dbContext.SubtitleToDeviceGroup.Where(i => !i.IsDel && i.SubtitleCode == model.Code).ToListAsync(); List <SubtitleToDeviceGroup> _OldDTG = new List <SubtitleToDeviceGroup>(); //待移除的设备 List <string> olddevice = new List <string>(); //数据库中已包含的设备 List <SubtitleToDeviceGroup> _NewDTG = new List <SubtitleToDeviceGroup>(); //待添加的设备 var dgname = string.Empty; //列表中不包含 移除 foreach (var gd in deviceGroups) { //dgname += gd.GName + ","; var devg = await dbContext.DeviceGroup.Where(i => i.Code == gd.GroupCode).FirstOrDefaultAsync(); dgname += devg.GName + ","; if (!model.GroupCode.Contains(gd.GroupCode)) { _OldDTG.Add(gd); } else { olddevice.Add(gd.GroupCode); } } //列表中不存在 添加 foreach (var device in model.GroupCode) { if (!olddevice.Contains(device)) { _NewDTG.Add(new SubtitleToDeviceGroup { AddTime = DateTime.Now, GroupCode = device, SubtitleCode = model.Code, IsDel = false, Code = Guid.NewGuid().ToString(), UpdateTime = DateTime.Now }); } } dbContext.SubtitleToDeviceGroup.RemoveRange(_OldDTG); dbContext.SubtitleToDeviceGroup.AddRange(_NewDTG); //var ip = Method.GetUserIp(this.HttpContext); //dbContext.SysLog.Add(new SysLog { AccountName = username, ModuleName = "发布模块", LogMsg = username + "发布字幕:" + subtitle.Name + "到设备组:" + dgname.TrimEnd(',') + "中。", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "修改", IP = ip }); await dbContext.SaveChangesAsync(); _Result.Code = "200"; _Result.Msg = "发布成功"; _Result.Data = ""; if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "发布成功"; _Result.Data = ""; } } catch (Exception e) { _Result.Code = "500"; _Result.Msg = "代码错误"; _Result.Data = e.ToString(); throw; } return(Json(_Result)); }
public async Task <IActionResult> Set(Input_SetSubtitle model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); try { Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_SetSubtitle)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } var mall = await dbContext.Mall.Where(i => i.Code == uol.MallCode).FirstOrDefaultAsync(); if (mall == null) { _Result.Code = "510"; _Result.Msg = "无效的商场编码"; _Result.Data = ""; return(Json(_Result)); } if (string.IsNullOrEmpty(model.Location)) { _Result.Code = "510"; _Result.Msg = "请输入字幕位置"; _Result.Data = ""; return(Json(_Result)); } if (string.IsNullOrEmpty(model.Name)) { _Result.Code = "510"; _Result.Msg = "请输入字幕名称"; _Result.Data = ""; return(Json(_Result)); } switch (model.Type.ToLower()) { case "regular": if (model.BeginTime > model.EndTime) { _Result.Code = "510"; _Result.Msg = "开始时间不能大于结束时间"; _Result.Data = ""; return(Json(_Result)); } //修正JS传回的标准时 model.BeginTime = model.BeginTime.AddHours(8); model.EndTime = model.EndTime.AddHours(8); model.Duration = 0; break; case "immediate": if (model.Duration <= 0) { _Result.Code = "510"; _Result.Msg = "时长需要大于0"; _Result.Data = ""; return(Json(_Result)); } model.BeginTime = DateTime.MinValue; model.EndTime = DateTime.MaxValue; break; default: _Result.Code = "510"; _Result.Msg = "请输入显示模式"; _Result.Data = ""; return(Json(_Result)); } var _subtitle = await dbContext.Subtitle.Where(i => !i.IsDel && i.MallCode == uol.MallCode && i.Name == model.Name).AsNoTracking().FirstOrDefaultAsync(); if (_subtitle != null) { if (_subtitle.Code != model.Code || string.IsNullOrEmpty(model.Code)) { _Result.Code = "510"; _Result.Msg = "字幕名称重复"; _Result.Data = ""; return(Json(_Result)); } } if (!string.IsNullOrEmpty(model.Code)) { var subtitle = await dbContext.Subtitle.Where(i => !i.IsDel && i.Code == model.Code).FirstOrDefaultAsync(); if (subtitle == null) { _Result.Code = "510"; _Result.Msg = "无效的字幕编码:" + model.Code; _Result.Data = ""; return(Json(_Result)); } else { subtitle.BeginTime = model.BeginTime; subtitle.EndTime = model.EndTime; subtitle.Text = model.Text; subtitle.Location = model.Location; subtitle.UpdateTime = DateTime.Now; subtitle.Type = model.Type; subtitle.Name = model.Name; subtitle.Duration = model.Duration; dbContext.Subtitle.Update(subtitle); } } else { var subtitle = new Subtitle() { AddTime = DateTime.Now, MallCode = uol.MallCode, BeginTime = model.BeginTime, Code = Guid.NewGuid().ToString(), Duration = model.Duration, Type = model.Type, EndTime = model.EndTime, IsDel = false, Location = model.Location, Text = model.Text, UpdateTime = DateTime.Now, Name = model.Name, }; dbContext.Subtitle.Add(subtitle); } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "设置成功"; _Result.Data = ""; } else { _Result.Code = "400"; _Result.Msg = "设置失败"; _Result.Data = ""; } } catch (Exception e) { _Result.Code = "500"; _Result.Msg = "代码错误"; _Result.Data = e.ToString(); throw; } return(Json(_Result)); }
public async Task <IActionResult> LiveCtr(Input_LiveCtr model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_LiveCtr)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); try { if (string.IsNullOrEmpty(model.Code)) { _Result.Code = "510"; _Result.Msg = "请输入编码"; _Result.Data = ""; return(Json(_Result)); } var live = await dbContext.Live.Where(i => !i.IsDel && i.Code == model.Code).AsNoTracking().FirstOrDefaultAsync(); if (live == null) { _Result.Code = "510"; _Result.Msg = "无效的直播编码"; _Result.Data = ""; return(Json(_Result)); } var ldlist = await dbContext.LiveToDev.Where(i => !i.IsDel).ToListAsync(); switch (model.Command.ToLower()) { case "start": live.BeingUsed = true; live.UpdateTime = DateTime.Now; dbContext.Live.Update(live); foreach (var ld in ldlist) { //发送命令到机器 var device = await dbContext.Device.Where(i => i.Code == ld.DevCode).FirstOrDefaultAsync(); if (device != null) { MsgTemplate msg = new MsgTemplate(); msg.SenderID = Method.ServerAddr; msg.ReceiverID = device.Code; msg.MessageType = "json"; msg.Content = new { Type = "Live", Data = new { Command = "start", Code = model.Code, live.Url } }; await Method.SendMsgAsync(msg); } } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "设置成功"; _Result.Data = ""; } break; case "cancel": live.BeingUsed = false; live.UpdateTime = DateTime.Now; dbContext.Live.Update(live); foreach (var ld in ldlist) { //发送命令到机器 var device = await dbContext.Device.Where(i => i.Code == ld.DevCode).FirstOrDefaultAsync(); if (device != null) { MsgTemplate msg = new MsgTemplate(); msg.SenderID = Method.ServerAddr; msg.ReceiverID = device.Code; msg.MessageType = "json"; msg.Content = new { Type = "Live", Data = new { Command = "cancel", Code = model.Code, live.Url } }; await Method.SendMsgAsync(msg); } } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "设置成功"; _Result.Data = ""; } break; default: _Result.Code = "510"; _Result.Msg = "无效的命令:" + model.Command; _Result.Data = ""; break; } } catch (Exception e) { _Result.Code = "500"; _Result.Msg = e.ToString(); _Result.Data = ""; throw; } return(Json(_Result)); }
public async Task <IActionResult> Add(Input_LiveAdd model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_LiveAdd)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } var mall = await dbContext.Mall.Where(i => i.Code == uol.MallCode).FirstOrDefaultAsync(); if (mall == null) { _Result.Code = "510"; _Result.Msg = "无效的商场编码"; _Result.Data = ""; return(Json(_Result)); } if (string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.Url) || string.IsNullOrEmpty(model.ScreenCode)) { _Result.Code = "510"; _Result.Msg = "参数不完整"; _Result.Data = ""; return(Json(_Result)); } var scr = dbContext.ScreenInfo.Where(i => i.Code == model.ScreenCode).FirstOrDefault(); if (scr == null) { _Result.Code = "510"; _Result.Msg = "无效的分辨率类型编码"; _Result.Data = ""; return(Json(_Result)); } Live live = new Live { AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), UpdateTime = DateTime.Now, MallCode = uol.MallCode, Name = model.Name, Url = model.Url, ScreenCode = model.ScreenCode, IsDel = false, BeingUsed = false }; dbContext.Live.Add(live); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "添加成功"; _Result.Data = ""; } else { _Result.Code = "2"; _Result.Msg = "添加失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> ParkingSpaceAdd(Input_ParkingSpace model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_ParkingSpace)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (string.IsNullOrEmpty(model.UserName)) { //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { model.UserName = uol.UserName; } } if (string.IsNullOrEmpty(model.ParkCode) || string.IsNullOrEmpty(model.Num) || string.IsNullOrEmpty(model.Xaxis) || string.IsNullOrEmpty(model.Yaxis) || string.IsNullOrEmpty(model.NavXaxis) || string.IsNullOrEmpty(model.NavYaxis)) { _Result.Code = "510"; _Result.Msg = "输入项中存在空值"; _Result.Data = ""; return(Json(_Result)); } var pk = await dbContext.ParkingLot.Where(i => i.Code == model.ParkCode && !i.IsDel).FirstOrDefaultAsync(); if (pk == null) { _Result.Code = "510"; _Result.Msg = "需要有效的停车场编码"; _Result.Data = ""; return(Json(_Result)); } model.Num = Regex.Replace(model.Num, ";", ";"); var numList = model.Num.Split(";"); var errorAlready = new ArrayList(); var spaceList = new List <ParkingSpace>(); foreach (var item in numList) { if (!string.IsNullOrEmpty(item)) { var numCount = await dbContext.ParkingSpace.Where(i => i.ParkCode == pk.Code && i.Num == item && !i.IsDel).CountAsync(); if (numCount > 0) { errorAlready.Add(item); } else { spaceList.Add(new ParkingSpace { AddTime = DateTime.Now, Num = item, ParkCode = pk.Code, Xaxis = model.Xaxis, Yaxis = model.Yaxis, NavXaxis = model.NavXaxis, NavYaxis = model.NavYaxis, Code = Guid.NewGuid().ToString(), IsDel = false, UpdateTime = DateTime.Now }); } } } //var pscount = await dbContext.ParkingSpace.Where(i => i.Num == model.Num && !i.IsDel).CountAsync(); //if (pscount > 0) if (errorAlready.Count > 0) { _Result.Code = "510"; _Result.Msg = "停车位编码:" + string.Join(";", (string[])errorAlready.ToArray(typeof(string))) + "已存在"; _Result.Data = ""; return(Json(_Result)); } dbContext.ParkingSpace.AddRange(spaceList); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "添加成功"; _Result.Data = ""; var ip = Method.GetUserIp(this.HttpContext); dbContext.SysLog.Add(new SysLog { AccountName = model.UserName, ModuleName = "停车场管理", LogMsg = model.UserName + "添加停车位", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "创建", IP = ip }); dbContext.SaveChanges(); } else { _Result.Code = "2"; _Result.Msg = "添加失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> ParkingSpaceDel(string code, string userName, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); if (string.IsNullOrEmpty(userName)) { //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { userName = uol.UserName; } } if (string.IsNullOrEmpty(code)) { _Result.Code = "510"; _Result.Msg = "请输入一个停车位编码"; _Result.Data = ""; return(Json(_Result)); } var ps = await dbContext.ParkingSpace.Where(i => i.Code == code && !i.IsDel).FirstOrDefaultAsync(); if (ps == null) { _Result.Code = "510"; _Result.Msg = "需要有效的停车位编码"; _Result.Data = ""; return(Json(_Result)); } ps.IsDel = true; ps.UpdateTime = DateTime.Now; dbContext.ParkingSpace.Update(ps); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "删除成功"; _Result.Data = ""; var ip = Method.GetUserIp(this.HttpContext); dbContext.SysLog.Add(new SysLog { AccountName = userName, ModuleName = "停车场管理", LogMsg = userName + "删除了编号为:" + ps.Num + "的停车位", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "删除", IP = ip }); dbContext.SaveChanges(); } else { _Result.Code = "2"; _Result.Msg = "删除失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> Add(Input_StoreNewsAdd model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); //检测用户登录情况 Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_StoreNewsAdd)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); DateTime dt = DateTime.Now; if (model.Imgs.Count() <= 0) { _Result.Code = "510"; _Result.Msg = "至少需要一张图片"; _Result.Data = ""; return(Json(_Result)); } if (model.ValidityPeriod == null) { model.ValidityPeriod = Convert.ToDateTime("3000-01-01"); } if (String.IsNullOrEmpty(model.UnionID)) { _Result.Code = "510"; _Result.Msg = "请输入有效的身份编码"; _Result.Data = ""; return(Json(_Result)); } var sacount = await dbContext.ShopAccount.Where(i => i.UnionID == model.UnionID).FirstOrDefaultAsync(); if (sacount == null) { _Result.Code = "510"; _Result.Msg = "请输入有效的身份编码"; _Result.Data = ""; return(Json(_Result)); } if (model.ValidityPeriod < DateTime.Now) { _Result.Code = "510"; _Result.Msg = "结束时间早于当前时间"; _Result.Data = ""; return(Json(_Result)); } if (model.Imgs.Count() > 10) { _Result.Code = "510"; _Result.Msg = "一条消息最多只能附加九张图片"; _Result.Data = ""; return(Json(_Result)); } var newscode = Guid.NewGuid().ToString(); //var isAutoPass = 2; var isAutoPass = 1; foreach (var img in model.Imgs) { var file = await dbContext.AssetFiles.Where(i => i.Code == img).FirstOrDefaultAsync(); if (file == null) { _Result.Code = "510"; _Result.Msg = "编码:" + img + ",不是有效的图片编码"; _Result.Data = ""; return(Json(_Result)); } //var suspiciousPicValue = ValidatePic.GetValidatePicValue(Method.ServerAddr + "MallSite" + file.FilePath).Result; // var suspiciousPicValue = ValidatePic.GetValidatePicValue(Method.OSSServer + file.FilePath).Result; var IsSuspicious = 0; if (!ValidatePic.GreenImg(Method.OSSServer + file.FilePath)) { IsSuspicious = 1; isAutoPass = 1; } dbContext.NewsImg.Add(new NewsImg { AddTime = dt, Code = Guid.NewGuid().ToString(), UpdateTime = dt, Img = img, NewsCode = newscode, IsSuspicious = Convert.ToBoolean(IsSuspicious) }); } var _PlacingNum = "SN" + Method.ConvertDateTimeInt(DateTime.Now).ToString() + Method.Number(2); StoreNews sn = new StoreNews { AddTime = dt, Code = newscode, News = model.News, ShopCode = sacount.ShopCode, ValidityPeriod = model.ValidityPeriod, UpdateTime = dt, AduitStatus = isAutoPass, MgrCode = "", Reason = "", PlacingNum = _PlacingNum }; dbContext.StoreNews.Add(sn); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "发布成功"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> Del(Input_DelRole model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_DelRole)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); //检测用户登录情况 UserOnLine userOnLine = Method.GetLoginUserName(dbContext, this.HttpContext); if (userOnLine == null || string.IsNullOrEmpty(userOnLine.UserCode)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } var _names = String.Empty; foreach (var c in model.Code) { var rcount = await dbContext.Roles.Where(i => i.Code == c).CountAsync(); if (rcount <= 0) { _Result.Code = "510"; _Result.Msg = "无效的角色编码:" + c; _Result.Data = ""; return(Json(_Result)); } var role = await dbContext.Roles.Where(i => i.Code == c).FirstOrDefaultAsync(); var urcount = await dbContext.UserRoles.Where(i => i.RoleCode == role.Code).CountAsync(); if (urcount > 0) { _Result.Code = "510"; _Result.Msg = "角色:" + role.Name + "正在被使用不可删除"; _Result.Data = ""; return(Json(_Result)); } if (role.Name == "超级管理员") { _Result.Code = "510"; _Result.Msg = "超级管理员不可删除"; _Result.Data = ""; return(Json(_Result)); } dbContext.Roles.Remove(role); dbContext.RolePermissions.RemoveRange(dbContext.RolePermissions.Where(i => i.RoleCode == role.Code)); _names += role.Name + ","; } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "删除成功"; _Result.Data = ""; var ip = Method.GetUserIp(this.HttpContext); dbContext.SysLog.Add(new SysLog { AccountName = userOnLine.UserName, ModuleName = "用户模块", LogMsg = userOnLine.UserName + "删除角色:" + _names.TrimEnd(','), AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "删除", IP = ip, MallCode = userOnLine.MallCode, SystemModule = "Mall" }); dbContext.SaveChanges(); } else { _Result.Code = "1"; _Result.Msg = "删除失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> Del(Input_GetNewsInfo model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); //检测用户登录情况 Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_GetNewsInfo)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (String.IsNullOrEmpty(model.UnionID)) { _Result.Code = "510"; _Result.Msg = "请输入有效的身份编码"; _Result.Data = ""; return(Json(_Result)); } var sacount = await dbContext.ShopAccount.Where(i => i.UnionID == model.UnionID).FirstOrDefaultAsync(); if (sacount == null) { _Result.Code = "510"; _Result.Msg = "请输入有效的身份编码"; _Result.Data = ""; return(Json(_Result)); } var news = await dbContext.StoreNews.Where(i => i.ShopCode == sacount.ShopCode && i.Code == model.NewsCode).FirstOrDefaultAsync(); if (news == null) { _Result.Code = "200"; _Result.Msg = "不存在的消息无需删除"; _Result.Data = ""; return(Json(_Result)); } dbContext.StoreNews.Remove(news); var Imgs = await dbContext.NewsImg.Where(i => i.NewsCode == news.Code).ToListAsync(); dbContext.NewsImg.RemoveRange(Imgs); if (await dbContext.SaveChangesAsync() > 0) { //删除文件 foreach (var img in Imgs) { await FileHelper.DelFile(img.Img, dbContext); } _Result.Code = "200"; _Result.Msg = "删除成功"; _Result.Data = ""; } else { _Result.Code = "2"; _Result.Msg = "删除失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> Edit(Input_BuildingEdit model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_BuildingEdit)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (String.IsNullOrEmpty(model.BuildingName)) { _Result.Code = "510"; _Result.Msg = "请输入楼栋名称"; _Result.Data = ""; return(Json(_Result)); } if (String.IsNullOrEmpty(model.BuildingCode)) { _Result.Code = "510"; _Result.Msg = "请输入楼栋编码"; _Result.Data = ""; return(Json(_Result)); } if (string.IsNullOrEmpty(model.MallCode)) { //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { model.MallCode = uol.MallCode; } } var mallbuild = await dbContext.MallBuilding.Where(i => i.BuildingCode == model.BuildingCode).FirstOrDefaultAsync(); var count = await dbContext.MallBuilding.Where(i => i.MallCode == mallbuild.MallCode).Join(dbContext.Building.Where(i => i.Name == model.BuildingName && i.Code != model.BuildingCode && !i.IsDel), ma => ma.BuildingCode, bu => bu.Code, (ma, bu) => bu).CountAsync(); if (count > 0) { _Result.Code = "510"; _Result.Msg = "楼栋名称重复"; _Result.Data = ""; return(Json(_Result)); } var Building = await dbContext.Building.Where(i => i.Code == model.BuildingCode).FirstOrDefaultAsync(); //var Building = await dbContext.BuildingInfo.Where(i => i.BuildingName == model.BuildingName).CountAsync(); if (Building == null) { _Result.Code = "510"; _Result.Msg = "楼栋不存在"; _Result.Data = ""; return(Json(_Result)); } Building.Name = model.BuildingName; Building.UpdateTime = DateTime.Now; dbContext.Building.Update(Building); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "更新成功"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> AuditState(Input_AuditState model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_AuditState)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); //检测用户登录情况 //var uol = Method.GetLoginUserName(dbContext, this.HttpContext); //if (string.IsNullOrEmpty(uol.UserName)) //{ // _Result.Code = "401"; // _Result.Msg = "请登陆后再进行操作"; // _Result.Data = ""; // return Json(_Result); //} if (string.IsNullOrEmpty(model.Code)) { _Result.Code = "401"; _Result.Msg = "请输入店铺信息编码"; _Result.Data = ""; return(Json(_Result)); } var storeNews = await dbContext.StoreNews.Where(i => i.Code == model.Code).FirstOrDefaultAsync(); if (storeNews == null) { _Result.Code = "401"; _Result.Msg = "店铺信息编码错误"; _Result.Data = ""; return(Json(_Result)); } if (model.State == 0) { _Result.Code = "401"; _Result.Msg = "请输入审核状态"; _Result.Data = ""; return(Json(_Result)); } if (model.State == 3) { if (string.IsNullOrEmpty(model.Reason)) { _Result.Code = "401"; _Result.Msg = "请输入拒绝理由"; _Result.Data = ""; return(Json(_Result)); } } storeNews.AduitStatus = model.State; storeNews.MgrCode = model.MgrCode; storeNews.UpdateTime = DateTime.Now; storeNews.Reason = string.IsNullOrEmpty(model.Reason) ? "" : model.Reason; dbContext.StoreNews.Update(storeNews); await dbContext.SaveChangesAsync(); _Result.Code = "200"; _Result.Msg = "审核成功"; _Result.Data = ""; return(Json(_Result)); }
public async Task <IActionResult> Del(Input_BuildingDel model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_BuildingDel)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (model.Code.Count() <= 0) { _Result.Code = "510"; _Result.Msg = "请输入楼栋编码"; _Result.Data = ""; return(Json(_Result)); } foreach (var c in model.Code) { var Building = await dbContext.Building.Where(i => i.Code == c).FirstOrDefaultAsync(); if (Building == null) { _Result.Code = "510"; _Result.Msg = "无效的编码:" + c; _Result.Data = ""; return(Json(_Result)); } var floorcount = await dbContext.Floor.Where(i => i.BuildingCode == c && !i.IsDel).CountAsync(); var shopcount = await dbContext.Shops.Where(i => i.BuildingCode == c && !i.IsDel).CountAsync(); var devcount = await dbContext.Device.Where(i => i.Building == c).CountAsync(); var allcount = floorcount + shopcount + devcount; if (allcount > 0) { _Result.Code = "510"; _Result.Msg = "楼栋:" + Building.Name + "正在使用中不可删除。"; _Result.Data = ""; return(Json(_Result)); } var mallBuilding = await dbContext.MallBuilding.Where(i => i.BuildingCode == c).FirstOrDefaultAsync(); Building.IsDel = true; Building.UpdateTime = DateTime.Now; dbContext.Building.Update(Building); //dbContext.MallBuilding.Remove(mallBuilding); } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "删除成功"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> SetScreensaver(Input_Screensaver model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_Screensaver)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } //var mall = await dbContext.Mall.Where(i => i.Code == uol.MallCode).FirstOrDefaultAsync(); //if (mall == null) //{ // _Result.Code = "510"; // _Result.Msg = "无效的商场编码"; // _Result.Data = ""; // return Json(_Result); //} //数据验证 if (model.Time == null) { _Result.Code = "510"; _Result.Msg = "无效的时间"; _Result.Data = ""; return(Json(_Result)); } //获取当前时间 var screensaver = await dbContext.Screensaver.Where(i => i.MallCode == uol.MallCode).FirstOrDefaultAsync(); //更改时间 if (screensaver == null) { dbContext.Screensaver.Add(new Screensaver { MallCode = uol.MallCode, Time = (int)model.Time, ScreenType = (int)model.ScreenType }); } else { screensaver.Time = (int)model.Time; screensaver.ScreenType = model.ScreenType.HasValue ? model.ScreenType.Value : 0; dbContext.Screensaver.Update(screensaver); } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "设置成功"; _Result.Data = ""; var deviceList = await dbContext.Device.Where(i => i.MallCode == uol.MallCode && !i.IsDelete).ToListAsync(); if (deviceList.Count > 0) { foreach (var item in deviceList) { MsgTemplate msg = new MsgTemplate(); msg.SenderID = Method.ServerAddr; msg.ReceiverID = item.Code; msg.MessageType = "json"; msg.Content = new { Type = "Screensaver", model.Time }; await Method.SendMsgAsync(msg); } } } else { _Result.Code = "2"; _Result.Msg = "设置失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> DelProgram(Input_ProgramDel model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); //检测用户登录情况 UserOnLine uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (uol == null || string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_ProgramDel)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); //判断字符串是否合法 if (model.Codes.Count() <= 0) { _Result.Code = "510"; _Result.Msg = "未能检测到编码"; _Result.Data = ""; return(Json(_Result)); } var pnames = string.Empty; //删除节目及节目组关系 try { List <Programs> list = new List <Programs>(); List <ProgramToGroup> _pgList = new List <ProgramToGroup>(); foreach (var item in model.Codes) { string ProgSrc = await dbContext.Programs.Where(i => i.Code == item).Select(s => s.ProgSrc).FirstOrDefaultAsync(); if (ProgSrc == null) { ProgSrc = string.Empty; } var path = string.Empty; string[] pathArry = ProgSrc.Split('\\'); for (int i = 0; i < pathArry.Length - 1; i++) { path += @"\" + pathArry[i]; } if (!string.IsNullOrEmpty(path)) { path = Method._hostingEnvironment.WebRootPath + path; //删除文件夹及其中的文件 if (Directory.Exists(path)) { DirectoryInfo di = new DirectoryInfo(path); di.Delete(true); } } var pro = dbContext.Programs.Where(i => i.Code == item).FirstOrDefault(); pnames += pro.ProgramName + ","; list.Add(pro); _pgList.AddRange(dbContext.ProgramToGroup.Where(i => i.ProgramCode == item)); } dbContext.Programs.RemoveRange(list); dbContext.ProgramToGroup.RemoveRange(_pgList); await dbContext.SaveChangesAsync(); _Result.Code = "200"; _Result.Msg = "删除成功"; _Result.Data = ""; //var ip = Method.GetUserIp(this.HttpContext); //dbContext.SysLog.Add(new SysLog { AccountName = username, ModuleName = "节目模块", LogMsg = username + "删除名称为:" + pnames.TrimEnd(',') + "的节目", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "删除", IP = ip }); // dbContext.SaveChanges(); return(Json(_Result)); } catch (Exception e) { _Result.Code = "500"; _Result.Msg = "Erro: " + e.ToString(); _Result.Data = ""; return(Json(_Result)); throw; } }
public async Task <IActionResult> ParkingLotDel(string code, string userNmae, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); if (string.IsNullOrEmpty(userNmae)) { //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { userNmae = uol.UserName; } } if (string.IsNullOrEmpty(code)) { _Result.Code = "510"; _Result.Msg = "请输入一个停车场编码"; _Result.Data = ""; return(Json(_Result)); } var pl = await dbContext.ParkingLot.Where(i => i.Code == code && !i.IsDel).FirstOrDefaultAsync(); if (pl == null) { _Result.Code = "510"; _Result.Msg = "需要有效的停车场ID"; _Result.Data = ""; return(Json(_Result)); } var count = await dbContext.ParkingSpace.Where(i => i.ParkCode == code && !i.IsDel).CountAsync(); if (count > 0) { _Result.Code = "510"; _Result.Msg = "该停车场有:" + count + "个停车位在使用不可移除"; _Result.Data = ""; return(Json(_Result)); } pl.IsDel = true; pl.UpdateTime = DateTime.Now; dbContext.ParkingLot.Update(pl); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "删除成功"; _Result.Data = ""; var floor = dbContext.Floor.Where(i => i.Code == code).FirstOrDefault(); var ip = Method.GetUserIp(this.HttpContext); dbContext.SysLog.Add(new SysLog { AccountName = userNmae, ModuleName = "停车场管理", LogMsg = userNmae + "将楼层编码为:" + code + "楼层名称为:" + floor == null ? "" : floor.Name + "的楼层从停车场移除", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "修改", IP = ip }); dbContext.SaveChanges(); } else { _Result.Code = "2"; _Result.Msg = "删除失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> UpdateGroupInfo(Input_GroupInfoNew model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); //检测用户登录情况 //string username = Method.GetLoginUserName(dbContext, this.HttpContext); //if (string.IsNullOrEmpty(username)) //{ // _Result.Code = "401"; // _Result.Msg = "请登陆后再进行操作"; // _Result.Data = ""; // return Json(_Result); //} Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_GroupInfoNew)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); //判断设备组是否有效 var grounps = await dbContext.DeviceGroup.Where(i => i.Code == model.Code).ToListAsync(); //更新信息 if (grounps.Count > 0) { var group = grounps.FirstOrDefault(); //检查组中的设备 if (model.Devices.Count() > 0) { var errorNoCodeList = new ArrayList(); var errorScreenList = new ArrayList(); var errorSyncList = new ArrayList(); var errorExistList = new ArrayList(); //判断ID是否都为有效设备 foreach (var item in model.Devices) { var dev = await dbContext.Device.Where(i => i.Code == item).FirstOrDefaultAsync(); if (dev == null) { errorNoCodeList.Add(item); } if (dev.ScreenInfo.ToLower() != group.ScreenInfoCode.ToLower()) { errorScreenList.Add(dev.IP); } if (dev.IsSyn != model.IsSync) { errorSyncList.Add(dev.DevNum); } if (model.IsSync) { var dgnum = await dbContext.DeviceToGroup.Where(i => i.DeviceCode == item && i.GroupCode != model.Code).CountAsync(); if (dgnum > 0) { errorExistList.Add(dev.DevNum); } } else { var dgnum = await dbContext.DeviceToGroup.Where(i => i.DeviceCode == item && i.GroupCode != model.Code).Join(dbContext.DeviceGroup.Where(i => i.Type == 2 && i.Code != model.Code), d => d.GroupCode, g => g.Code, (d, g) => d).CountAsync(); if (dgnum > 0) { errorExistList.Add(dev.DevNum); } } } if (errorNoCodeList.Count > 0) { _Result.Code = "510"; _Result.Msg = "没有编码为:" + string.Join(";", (string[])errorNoCodeList.ToArray(typeof(string))) + "的设备"; _Result.Data = ""; return(Json(_Result)); } if (errorScreenList.Count > 0) { _Result.Code = "510"; _Result.Msg = "IP为:" + string.Join(";", (string[])errorScreenList.ToArray(typeof(string))) + "的设备屏幕分辨率与设备组分辨率不一致"; _Result.Data = ""; return(Json(_Result)); } if (errorSyncList.Count > 0) { _Result.Code = "510"; _Result.Msg = "设备名:" + string.Join(";", (string[])errorSyncList.ToArray(typeof(string))) + "的设备同步属性与设备组属性不一致"; _Result.Data = ""; return(Json(_Result)); } if (errorExistList.Count > 0) { _Result.Code = "510"; if (model.IsSync) { _Result.Msg = "设备名为:" + string.Join(";", (string[])errorExistList.ToArray(typeof(string))) + "的设备已存在于其他设备组"; } else { _Result.Msg = "设备名为:" + string.Join(";", (string[])errorExistList.ToArray(typeof(string))) + "的设备已存在于其他同步设备组"; } _Result.Data = ""; return(Json(_Result)); } } //获取设备组 到设备关系列表 var groupdevices = await dbContext.DeviceToGroup.Where(i => i.GroupCode == model.Code).ToListAsync(); List <DeviceToGroup> _OldDTG = new List <DeviceToGroup>(); //待移除的设备 List <string> olddevice = new List <string>(); //数据库中已包含的设备 List <DeviceToGroup> _NewDTG = new List <DeviceToGroup>(); //待添加的设备 //列表中不包含 移除 foreach (var gd in groupdevices) { if (!model.Devices.Contains(gd.DeviceCode)) { _OldDTG.Add(gd); } else { olddevice.Add(gd.DeviceCode); } } //列表中不存在 添加 foreach (var device in model.Devices) { if (!olddevice.Contains(device)) { _NewDTG.Add(new DeviceToGroup { AddTime = DateTime.Now, DeviceCode = device, GroupCode = group.Code, Code = Guid.NewGuid().ToString(), UpdateTime = DateTime.Now }); } } //修改设备组名称 group.GName = model.GName; dbContext.DeviceGroup.Update(group); dbContext.DeviceToGroup.RemoveRange(_OldDTG); dbContext.DeviceToGroup.AddRange(_NewDTG); //操作成功 if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "更新设备组信息成功"; _Result.Data = ""; //var ip = Method.GetUserIp(this.HttpContext); //dbContext.SysLog.Add(new SysLog { AccountName = username, ModuleName = "设备组模块", LogMsg = username + "更新设备组:" + group.GName + "的信息", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "修改", IP = ip }); // dbContext.SaveChanges(); // var _thisjobId = BackgroundJob.Schedule(() => SynData.SendDevInfo(), TimeSpan.FromSeconds(1)); } else { _Result.Code = "3"; _Result.Msg = "更新设备组信息失败"; _Result.Data = ""; } } else { _Result.Code = "4"; _Result.Msg = "无效的设备组"; _Result.Data = ""; } //返回操作结果 return(Json(_Result)); }
public async Task <IActionResult> ParkingLotEdit(Input_PLEdit model, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_PLEdit)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (string.IsNullOrEmpty(model.MallCode)) { //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { model.UserName = uol.UserName; model.MallCode = uol.MallCode; } } if (model.FloorCodes.Count() <= 0) { var spacecount = await dbContext.MallBuilding.Where(i => i.MallCode == model.MallCode).Join( dbContext.Building.Where(i => !i.IsDel), mb => mb.BuildingCode, bu => bu.Code, (mb, bu) => bu).Join( dbContext.Floor.Where(i => !i.IsDel), bu => bu.Code, fl => fl.BuildingCode, (bu, fl) => fl).Join( dbContext.ParkingLot.Where(i => !i.IsDel), fl => fl.Code, pl => pl.FloorCode, (fl, pl) => pl).Join( dbContext.ParkingSpace.Where(i => !i.IsDel), pl => pl.Code, ps => ps.ParkCode, (pl, ps) => ps ).AsNoTracking().CountAsync(); //var spacecount = await dbContext.ParkingSpace.Where(i => !i.IsDel).CountAsync(); if (spacecount > 0) { _Result.Code = "510"; _Result.Msg = "Erro:有" + spacecount + "个停车位正在被使用不可将停车场清空"; _Result.Data = ""; return(Json(_Result)); } // var pllist = dbContext.ParkingLot.Where(i => !i.IsDel).ToList(); var pllist = await dbContext.MallBuilding.Where(i => i.MallCode == model.MallCode).Join( dbContext.Building.Where(i => !i.IsDel), mb => mb.BuildingCode, bu => bu.Code, (mb, bu) => bu).Join( dbContext.Floor.Where(i => !i.IsDel), bu => bu.Code, fl => fl.BuildingCode, (bu, fl) => fl).Join( dbContext.ParkingLot.Where(i => !i.IsDel), fl => fl.Code, pl => pl.FloorCode, (fl, pl) => pl).AsNoTracking().ToListAsync(); foreach (var pl in pllist) { pl.IsDel = true; pl.UpdateTime = DateTime.Now; } dbContext.ParkingLot.UpdateRange(pllist); await dbContext.SaveChangesAsync(); _Result.Code = "200"; _Result.Msg = "编辑成功"; _Result.Data = ""; return(Json(_Result)); } foreach (var item in model.FloorCodes) { if (string.IsNullOrEmpty(item)) { _Result.Code = "510"; _Result.Msg = "Erro:编码不可为空"; _Result.Data = ""; return(Json(_Result)); } var floor = await dbContext.Floor.Where(i => i.Code == item).AsNoTracking().FirstOrDefaultAsync(); if (floor == null) { _Result.Code = "510"; _Result.Msg = "需要有效的楼层编码"; _Result.Data = ""; return(Json(_Result)); } } // var pls = await dbContext.ParkingLot.Where(i => !i.IsDel).ToListAsync(); var pls = await dbContext.MallBuilding.Where(i => i.MallCode == model.MallCode).Join( dbContext.Building.Where(i => !i.IsDel), mb => mb.BuildingCode, bu => bu.Code, (mb, bu) => bu).Join( dbContext.Floor.Where(i => !i.IsDel), bu => bu.Code, fl => fl.BuildingCode, (bu, fl) => fl).Join( dbContext.ParkingLot.Where(i => !i.IsDel), fl => fl.Code, pl => pl.FloorCode, (fl, pl) => pl).AsNoTracking().ToListAsync(); bool haschange = false; foreach (var pl in pls) { //ID不在新的列表中 删除 if (model.FloorCodes.Where(i => i == pl.FloorCode).Count() <= 0) { var scount = await dbContext.ParkingSpace.Where(i => i.ParkCode == pl.Code && !i.IsDel).CountAsync(); if (scount > 0) { var floor = await dbContext.Floor.Where(i => i.Code == pl.FloorCode && !i.IsDel).FirstOrDefaultAsync(); var bu = await dbContext.Building.Where(i => i.Code == floor.BuildingCode && !i.IsDel).FirstOrDefaultAsync(); var plName = bu.Name + floor.Name; _Result.Code = "510"; _Result.Msg = "Erro:停车场" + plName + "有" + scount + "个停车位正在被使用,不可移除"; _Result.Data = ""; return(Json(_Result)); } pl.IsDel = true; pl.UpdateTime = DateTime.Now; dbContext.ParkingLot.Update(pl); haschange = true; } } foreach (var code in model.FloorCodes) { //ID不在旧的列表中 添加 if (pls.Where(i => i.FloorCode == code).Count() <= 0) { dbContext.ParkingLot.Add(new ParkingLot { AddTime = DateTime.Now, FloorCode = code, IsDel = false, Code = Guid.NewGuid().ToString(), UpdateTime = DateTime.Now }); haschange = true; } } if (!haschange) { _Result.Code = "200"; _Result.Msg = "无数据变更"; _Result.Data = ""; return(Json(_Result)); } if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "添加成功"; _Result.Data = ""; var ip = Method.GetUserIp(this.HttpContext); dbContext.SysLog.Add(new SysLog { AccountName = model.UserName, ModuleName = "停车场管理", LogMsg = model.UserName + "编辑停车场信息", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "修改", IP = ip }); dbContext.SaveChanges(); } else { _Result.Code = "2"; _Result.Msg = "添加失败"; _Result.Data = ""; } return(Json(_Result)); }
public async Task <IActionResult> LoginBySMS(Input_LoginViewModelBySMS model, [FromServices] ContextString dbContext, string returnUrl = null) { QianMuResult _Result = new QianMuResult(); Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Request.ContentLength.Value]; stream.Read(buffer, 0, buffer.Length); string inputStr = Encoding.UTF8.GetString(buffer); model = (Input_LoginViewModelBySMS)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType()); if (string.IsNullOrEmpty(model.Phone) || string.IsNullOrEmpty(model.vercode)) { _Result.Code = "510"; _Result.Msg = "请输入手机号和验证码"; _Result.Data = ""; return(Json(_Result)); } //判断系统中是否存在用户 var accnum = dbContext.Account.Where(i => i.Phone == model.Phone && i.Activity == true).Count(); if (accnum <= 0) { _Result.Code = "1"; _Result.Msg = "用户不存在或不可用"; _Result.Data = ""; return(Json(_Result)); } var count = await dbContext.PhoneRecord.Where(i => i.Phone == model.Phone && i.VerCode == model.vercode).CountAsync(); if (count > 0) { var pr = await dbContext.PhoneRecord.Where(i => i.Phone == model.Phone).OrderByDescending(o => o.AddTime).FirstOrDefaultAsync(); if (pr.VerCode == model.vercode && pr.UpdateTime >= DateTime.Now.AddMinutes(-5)) { pr.Status = true; pr.UpdateTime = DateTime.Now; dbContext.PhoneRecord.Update(pr); if (await dbContext.SaveChangesAsync() > 0) { Account _User = dbContext.Account.Where(i => i.Phone == model.Phone).FirstOrDefault(); string _LoginSession = Guid.NewGuid().ToString(); //会话唯一标记 //保存会话状态 var _InvalidTime = DateTime.Now.AddDays(1); if (model.RememberMe == "on") { _InvalidTime = DateTime.Now.AddDays(7); } //更新用户信息 var ip = Method.GetUserIp(this.HttpContext); string _LastLoginIP = ip; DateTime _LastLoginTime = DateTime.Now; _User.InvalidTime = _InvalidTime; _User.LoginSession = _LoginSession; _User.LastLoginTime = _LastLoginTime; _User.LastLoginIP = _LastLoginIP; dbContext.Account.Update(_User); dbContext.SaveChanges(); //日志记录 try { dbContext.SysLog.Add(new SysLog { AccountName = _User.AccountName, ModuleName = "用户模块", LogMsg = _User.AccountName + "登陆了系统", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "登录", IP = ip, SystemModule = _User.SystemModule, MallCode = _User.MallCode }); dbContext.SaveChanges(); } catch (Exception e) { QMLog qm = new QMLog(); qm.WriteLogToFile("", e.ToString()); } _Result.Code = "200"; _Result.Msg = "登陆成功"; _Result.Data = _LoginSession; } else { _Result.Code = "2"; _Result.Msg = "用户名或密码不正确"; _Result.Data = ""; } } else { _Result.Code = "2"; _Result.Msg = "验证码不正确"; _Result.Data = ""; } } return(Json(_Result)); }
public async Task <IActionResult> ParkingLotAdd(string FloorCode, string userNmae, [FromServices] ContextString dbContext) { QianMuResult _Result = new QianMuResult(); if (string.IsNullOrEmpty(userNmae)) { //检测用户登录情况 var uol = Method.GetLoginUserName(dbContext, this.HttpContext); if (string.IsNullOrEmpty(uol.UserName)) { _Result.Code = "401"; _Result.Msg = "请登陆后再进行操作"; _Result.Data = ""; return(Json(_Result)); } else { userNmae = uol.UserName; } } if (string.IsNullOrEmpty(FloorCode)) { _Result.Code = "510"; _Result.Msg = "请输入一个楼层编码"; _Result.Data = ""; return(Json(_Result)); } var floor = await dbContext.Floor.Where(i => i.Code == FloorCode && !i.IsDel).FirstOrDefaultAsync(); if (floor == null) { _Result.Code = "510"; _Result.Msg = "需要有效的楼层ID"; _Result.Data = ""; return(Json(_Result)); } dbContext.ParkingLot.Add(new ParkingLot { AddTime = DateTime.Now, FloorCode = FloorCode, IsDel = false, Code = Guid.NewGuid().ToString(), UpdateTime = DateTime.Now }); if (await dbContext.SaveChangesAsync() > 0) { _Result.Code = "200"; _Result.Msg = "添加成功"; _Result.Data = ""; } else { _Result.Code = "2"; _Result.Msg = "添加失败"; _Result.Data = ""; } var ip = Method.GetUserIp(this.HttpContext); dbContext.SysLog.Add(new SysLog { AccountName = userNmae, ModuleName = "停车场管理", LogMsg = userNmae + "将楼层Code为:" + FloorCode + ",楼层名称为:" + floor.Name + "的楼层标记为停车场", AddTime = DateTime.Now, Code = Guid.NewGuid().ToString(), Type = "修改", IP = ip }); dbContext.SaveChanges(); return(Json(_Result)); }