/// <summary> /// Add location to existing citizen /// </summary> /// <param name="citizenId"></param> /// <param name="locationId"></param> /// <returns></returns> public async Task <ResultBase> AddLocation(int citizenId, int locationId) { try { var citizen = await this.Db.Citizens.SingleOrDefaultAsync(x => x.Id == citizenId); if (citizen == null) { return(ResultBase.Failure("Citizen not found.")); } var location = await this.Db.Locations.SingleOrDefaultAsync(x => x.Id == locationId); if (location == null) { return(ResultBase.Failure("Location not found.")); } citizen.LocationId = location.Id; await this.Db.SaveChangesAsync(); return(ResultBase.Success()); } catch (Exception exception) { Log.Logger.Error(exception, "Error in AddLocation method."); return(ResultBase.Failure("Error in AddLocation method.")); } }
/// <summary> /// Update existing citizen. /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <ResultBase> UpdateAsync(CitizenDto model) { try { if (model == null) { return(ResultBase.Failure("Model is empty.")); } var citizen = await this.Db.Citizens.SingleOrDefaultAsync(x => x.Id == model.Id); if (citizen == null) { return(ResultBase.Failure("Citizen not found.")); } citizen.Update(model); await this.Db.SaveChangesAsync(); return(ResultBase.Success()); } catch (ArgumentException argumentException) { return(ResultBase.Failure(argumentException.Message)); } catch (Exception exception) { Log.Logger.Error(exception, "Error in Citizen Update method."); return(ResultBase.Failure($"Error in Citizen Update method.")); } }
/// <summary> /// Delete existing citizen. /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ResultBase> DeleteAsync(int id) { try { if (id <= 0) { return(ResultBase.Failure("Invalid id.")); } var citizen = await this.Db.Citizens.SingleOrDefaultAsync(x => x.Id == id); if (citizen == null) { return(ResultBase.Failure("Citizen not found.")); } this.Db.Citizens.Remove(citizen); await this.Db.SaveChangesAsync(); return(ResultBase.Success()); } catch (Exception exception) { Log.Logger.Error(exception, "Error in Citizen Delete method."); return(ResultBase.Failure($"Error in Citizen Delete method.")); } }
public async Task <IActionResult> Save([FromBody] RoleSaveDto dto) { if (dto.Id.HasValue && dto.Id.Value != Guid.Empty) { await _roleAppService.UpdateAsync(dto); } else { await _roleAppService.CreateAsync(dto); } return(Json(ResultBase.Success())); }
/// <summary> /// 上传附件 /// </summary> /// <param name="logger"></param> /// <returns></returns> public ResultBase <string> StartUploadAttachmentItem(Logger logger) { if (dicData == null || dicData.Count == 0) { return(ResultBase <string> .Failure("json数据为空或者数据格式错误")); } customId = GetCustomId(); itemName = GetItemName(); pk = GetPrimaryKey(); //判断能否上传 bool canUpload = CanClientUploadData(customId); if (!canUpload) { string error = "Blacklist! Restrict Upload!"; string message = string.Format("[{0}]-[{1}]-[{2}]", error, GetTableName(), dicData); LoggerHelper.WriteCustomLog(logger, message, customId, false); return(ResultBase <string> .Failure(error)); } //判断是否有主键 if (string.IsNullOrWhiteSpace(pk)) { string error = "Data Has No PrimaryKey"; string message = string.Format("[{0}]-[{1}]-[{2}]", error, GetTableName(), dicData); LoggerHelper.WriteCustomLog(logger, message, customId, false); return(ResultBase <string> .Failure(error)); } string filePath = string.Empty; string errorMsg = string.Empty; bool isPrePushMqSucc = PrePushToRabbitMq(out filePath, out errorMsg); if (!isPrePushMqSucc) { string message = string.Format("[{0}]-[{1}]-[{2}]", errorMsg, GetTableName(), dicData); LoggerHelper.WriteCustomLog(logger, message, customId, false); return(ResultBase <string> .Failure(errorMsg)); } else { string message = string.Format("[{0}]-[{1}]", GetTableName(), dicData); LoggerHelper.WriteCustomLog(logger, message, customId, true); return(ResultBase <string> .Success(filePath)); } }
/// <summary> /// Update existing issue. /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <ResultBase> UpdateAsync(IssueDto model) { try { if (model == null) { return(ResultBase.Failure("Model is empty.")); } var citizen = await this.Db.Citizens.SingleOrDefaultAsync(x => x.Id == model.CitizenId); if (citizen == null) { return(ResultBase.Failure("Citizen not found. Citizen is required to update an existing issue.")); } var location = await this.Db.Locations.SingleOrDefaultAsync(x => x.Id == model.LocationId); if (location == null) { return(ResultBase.Failure("Location not found. Location is required to update an existing issue.")); } var issue = await this.Db.Issues.SingleOrDefaultAsync(x => x.Id == model.Id); if (issue == null) { return(ResultBase.Failure("Issue not found.")); } issue.Update(model); await this.Db.SaveChangesAsync(); return(ResultBase.Success()); } catch (ArgumentException argumentException) { return(ResultBase.Failure(argumentException.Message)); } catch (Exception exception) { Log.Logger.Error(exception, "Error in Issue Update method."); return(ResultBase.Failure($"Error in Issue Update method.")); } }
/// <summary> /// Delete existing location. /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ResultBase> DeleteAsync(int id) { try { if (id <= 0) { return(ResultBase.Failure("Invalid id.")); } var issueCount = await this.Db.Issues.Where(x => x.LocationId == id).CountAsync(); if (issueCount > 0) { return(ResultBase.Failure($"Location can not be deleted. This location is associated with {issueCount} issues.")); } var citizenCount = await this.Db.Citizens.Where(x => x.LocationId == id).CountAsync(); if (citizenCount > 0) { return(ResultBase.Failure($"Location can not be deleted. This location is associated with {citizenCount} citizens.")); } var location = await this.Db.Locations.SingleOrDefaultAsync(x => x.Id == id); if (location == null) { return(ResultBase.Failure("Location not found.")); } this.Db.Locations.Remove(location); await this.Db.SaveChangesAsync(); return(ResultBase.Success()); } catch (Exception exception) { Log.Logger.Error(exception, "Error in Location Delete method."); return(ResultBase.Failure($"Error in Location Delete method.")); } }
/// <summary> /// Update existing location from AddressDto. /// </summary> /// <param name="model">AddressDto</param> /// <returns></returns> public async Task <ResultBase> UpdateAsync(AddressDto model) { try { if (model == null) { return(ResultBase.Failure("Model is empty.")); } var state = await this.Db.States.SingleOrDefaultAsync(x => x.Id == model.StateId); if (state == null) { return(ResultBase.Failure("State not found. State is required to update existing address location.")); } var location = await this.Db.Locations.SingleOrDefaultAsync(x => x.Id == model.Id); if (location == null) { return(ResultBase.Failure("Location not found.")); } location.Update(model); await this.Db.SaveChangesAsync(); return(ResultBase.Success()); } catch (ArgumentException argumentException) { return(ResultBase.Failure(argumentException.Message)); } catch (Exception exception) { Log.Logger.Error(exception, "Error in Location Update AddressDto method."); return(ResultBase.Failure($"Error in Location Update AddressDto method.")); } }
public async Task <ResultBase> Authenticate([FromBody] WxAuthenticateInputModel input) { await _userAppService.wxAuthorize(input.NickName, input.HeadImg); return(ResultBase.Success()); }
public async Task <IActionResult> AddAsync() { await _handleLogService.AddAsync(); return(Json(ResultBase.Success())); }
/// <summary> /// 推送数据到MQ 不处理附件 /// </summary> /// <param name="logger"></param> /// <returns></returns> public ResultBase <string> StartUploadDataItem(Logger logger) { if (dicData == null || dicData.Count == 0) { return(ResultBase <string> .Failure("json数据为空或者数据格式错误")); } customId = GetCustomId(); itemName = GetItemName(); filePath = GetFilePath(); pk = GetPrimaryKey(); //判断能否上传 bool canUpload = CanClientUploadData(customId); if (!canUpload) { string error = "Blacklist! Restrict Upload!"; string message = string.Format("[{0}]-[{1}]-[{2}]", error, GetTableName(), dicData); LoggerHelper.WriteCustomLog(logger, message, customId, false); return(ResultBase <string> .Failure(error)); } //判断是否有主键 if (string.IsNullOrWhiteSpace(pk)) { string error = "Data Has No PrimaryKey"; string message = string.Format("[{0}]-[{1}]-[{2}]", error, GetTableName(), dicData); LoggerHelper.WriteCustomLog(logger, message, customId, false); return(ResultBase <string> .Failure(error)); } //是否有附件的上传保存路径 if (needFilePath && string.IsNullOrWhiteSpace(filePath)) { string error = "Attachment FilePath Is Empty"; string message = string.Format("[{0}]-[{1}]-[{2}]", error, GetTableName(), dicData); LoggerHelper.WriteCustomLog(logger, message, customId, false); return(ResultBase <string> .Failure(error)); } JObject jobj = ConstructNeedToBePushedJson(); if (!string.IsNullOrWhiteSpace(customId)) { jobj["CUSTOMID"] = customId; } jobj.Add(new JProperty("PK", pk)); PostConstructJson(jobj); string errorMsg = string.Empty; bool isPushToMqSucc = PushJsonToMq(jobj, out errorMsg); if (!isPushToMqSucc) { string message = string.Format("[{0}]-[{1}]-[{2}]", errorMsg, GetTableName(), dicData); LoggerHelper.WriteCustomLog(logger, message, customId, false); return(ResultBase <string> .Failure(errorMsg)); } else { string message = string.Format("[{0}]-[{1}]", GetTableName(), dicData); LoggerHelper.WriteCustomLog(logger, message, customId, true); return(ResultBase <string> .Success()); } }
public async Task <IActionResult> Save([FromBody] ManagerSaveDto dto) { await _managerAppService.SaveAsync(dto); return(Json(ResultBase.Success())); }
public async Task <JsonResult> ChangeHead(Guid headId) { await _userAppService.ChangeHead(headId); return(Json(ResultBase.Success())); }
/// <summary> /// 修改状态 /// </summary> /// <param name="headId"></param> /// <param name="status"></param> /// <returns></returns> public async Task <JsonResult> ChangeStatus(Guid headId, Status status) { await _headAppService.ChangeStatus(headId, status); return(Json(ResultBase.Success())); }
public async Task <JsonResult> BatchDelete([FromBody] List <Guid> ids) { await _managerAppService.BatchDeleteAsync(ids); return(Json(ResultBase.Success())); }
public async Task <IActionResult> Add([FromBody] EvaluateAddInputDto dto) { await _evaluateAppService.Add(dto); return(Json(ResultBase.Success())); }
public async Task <JsonResult> Delete(Guid id) { await _evaluateAppService.Delete(id); return(Json(ResultBase.Success())); }
public async Task <IActionResult> Save([FromBody] ProductSaveDto dto) { await _productAppService.SaveAsync(dto); return(Json(ResultBase.Success())); }
public async Task <JsonResult> ChangEnable(Guid id, bool status) { await _productAppService.ChangEnable(id, status); return(Json(ResultBase.Success())); }
public async Task <JsonResult> Delete(Guid id) { await _productAppService.DeleteAsync(id); return(Json(ResultBase.Success())); }