Exemplo n.º 1
0
        /// <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."));
            }
        }
Exemplo n.º 2
0
        /// <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."));
            }
        }
Exemplo n.º 3
0
        /// <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."));
            }
        }
Exemplo n.º 4
0
        public ResultBase <string> SyncPKPMJCData(string tableName, Dictionary <string, string> cmdData, byte[] cmdAttach)
        {
            if (updateNow)
            {
                return(ResultBase <string> .Failure("服务器在处理数据,暂时不接收数据!"));
            }

            try
            {
                string retStr = string.Empty;
                tableName = GetPlatTableName(tableName);
                UploadMqbaseItem item = GetUploadItemByTableName(tableName, cmdData, cmdAttach);
                if (item == null)
                {
                    string message = string.Format("[{0}]-[{1}]", "无配置的表上传", tableName, cmdData);
                    LoggerHelper.WriteCustomLog(logger, message, "NoTableConfig", false);
                    return(ResultBase <string> .Failure(message));
                }
                else
                {
                    return(item.StartUploadDataItem(logger));
                }
            }
            catch (Exception ex)
            {
                string retStr = ex.Message.ToString() + ex.StackTrace.ToString() + ex.Source.ToString();
                LoggerHelper.WriteErrorLog(logger, ex);
                return(ResultBase <string> .Failure(retStr));
            }
        }
Exemplo n.º 5
0
        /// <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));
            }
        }
Exemplo n.º 6
0
        /// <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."));
            }
        }
Exemplo n.º 7
0
        /// <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."));
            }
        }
Exemplo n.º 8
0
        /// <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."));
            }
        }
Exemplo n.º 9
0
        /// <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());
            }
        }