public async Task <JsonResult> CreateTask([FromBody] TaskOutDto task) { CheckApiKey(); using (var sqlR = new DeviceTaskRepository(_logger)) { var ret = new InsertResDto(); try { await sqlR.CreateTask(task); ret.IsSuccess = true; } catch (Exception e) { ret.Error = e.Message; if (e is SqlException sqle) { if (sqle.Number == 2601 && sqle.Message.ToLower().Contains("refid")) { ret.AlreadyExist = true; ret.Error = "already exist"; } } } return(Json(ret)); } }
public async Task <JsonResult> GetAllStatuses() { await CheckPermission(); using (var rep = new DeviceTaskRepository()) { var result = rep.GetAllStatuses(); return(Json(result)); } }
public async Task <JsonResult> GetById(int id) { await CheckPermission(); using (var rep = new DeviceTaskRepository()) { var result = await rep.GetById(id); return(Json(result)); } }
public async Task <JsonResult> GetTable([FromBody] DeviceTaskRequest input) { await CheckPermission(); using (var rep = new DeviceTaskRepository(_logger)) { var result = await rep.GetTable(input); return(Json(result)); } }
public async Task SaveCommentAndStatus([FromBody] DeviceTaskCommentDto input) { await CheckPermission(); var user = await GetCurrentUser(); using (var rep = new DeviceTaskRepository()) { input.User = user; input.Date = DateTime.Now; await rep.SaveCommentAndStatus(input); } }
public async Task <JsonResult> Add([FromBody] DeviceTaskDto input) { await CheckPermission(); var user = await GetCurrentUser(); using (var rep = new DeviceTaskRepository()) { input.User = new ClassifierDto { Id = user.Id }; input.CreateDate = DateTime.Now; var result = await rep.Add(input); return(Json(result)); } }
public async Task Delete(int id) { await CheckPermission(); using (var rep = new DeviceRepository(_logger)) { using (var rept = new DeviceTaskRepository(_logger)) { var cnt = await rept.GetDeviceOpenTaskCount(id); if (cnt > 0) { throw new Exception("Запрещено удалять устройство,е сли есть открытые задачи"); } await rep.Delete(id); } } }