Example #1
0
        /// <summary>
        /// Method to built an Alert from a DbTaskResult
        /// </summary>
        /// <param name="result"></param>
        public void SetAlert(DbTaskResult result)
        {
            this.Message = result.Message;
            this.IsAlert = true;
            switch (result.Type)
            {
            case MessageType.Error:
                this.ColourCode = Bootstrap.ColourCode.danger;
                break;

            case MessageType.Information:
                this.ColourCode = Bootstrap.ColourCode.info;
                break;

            case MessageType.Success:
                this.ColourCode = Bootstrap.ColourCode.success;
                break;

            case MessageType.Warning:
                this.ColourCode = Bootstrap.ColourCode.warning;
                break;

            default:
                this.ColourCode = Bootstrap.ColourCode.primary;
                this.IsAlert    = false;
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Method to execute a stored procedure against the dataservice
        /// </summary>
        /// <param name="record"></param>
        /// <param name="spType"></param>
        /// <returns></returns>
        protected async Task <DbTaskResult> RunStoredProcedure(TRecord record, SPType spType)
        {
            var ret = new DbTaskResult()
            {
                Message = $"Error saving {this.RecordConfiguration.RecordDescription}",
                IsOK    = false,
                Type    = MessageType.Error
            };

            var spname = spType switch
            {
                SPType.Create => this.RecordInfo.CreateSP,
                SPType.Update => this.RecordInfo.UpdateSP,
                SPType.Delete => this.RecordInfo.DeleteSP,
                _ => string.Empty
            };
            var parms = this.GetSQLParameters(record, spType);

            if (await this.DBContext.CreateDbContext().ExecStoredProcAsync(spname, parms))
            {
                var idparam = parms.FirstOrDefault(item => item.Direction == ParameterDirection.Output && item.SqlDbType == SqlDbType.Int && item.ParameterName.Contains("ID"));
                ret = new DbTaskResult()
                {
                    Message = $"{this.RecordConfiguration.RecordDescription} saved",
                    IsOK    = true,
                    Type    = MessageType.Success
                };
                if (idparam != null)
                {
                    ret.NewID = Convert.ToInt32(idparam.Value);
                }
            }
            return(ret);
        }
Example #3
0
        /// <summary>
        /// Inherited IDataService Method
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public override Task <DbTaskResult> CreateRecordAsync(DbWeatherStation record)
        {
            record.ID = this.Records.Max(item => item.ID) + 1;
            this.Records.Add(record);
            var result = new DbTaskResult()
            {
                IsOK = true, NewID = record.ID, Message = "Record Added", Type = MessageType.Success
            };

            return(Task.FromResult(result));
        }
Example #4
0
        /// <summary>
        /// Inherited IDataService Method
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public override async Task <DbTaskResult> UpdateRecordAsync(DbWeatherStation record)
        {
            var rec = await GetRecordAsync(record.ID);

            if (rec != null)
            {
                rec = record;
            }
            var result = new DbTaskResult()
            {
                IsOK = rec != null, NewID = 0
            };

            result.Message = rec != null ? "Record Updated" : "Record could not be found";
            result.Type    = rec != null ? MessageType.Success : MessageType.Error;
            return(result);
        }
Example #5
0
        /// <summary>
        /// Inherited IDataService Method
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <DbTaskResult> DeleteRecordAsync(int id)
        {
            var rec = await GetRecordAsync(id);

            var isrecord = rec != null;

            if (isrecord)
            {
                this.Records.Remove(rec);
            }
            var result = new DbTaskResult()
            {
                IsOK = isrecord, NewID = 0
            };

            result.Message = isrecord ? "Record Deleted" : "Record could not be found";
            result.Type    = isrecord ? MessageType.Success : MessageType.Error;
            return(result);
        }