/// <summary> /// Takes the received Retaurants Sales object, creates the HourlyRecordModel objects then sends them to the DataAccess layer /// </summary> /// <param name="sales">Incoming Sales object</param> /// <returns>The Restaurant # that was received</returns> public int UploadData(RestaurantSales sales) { foreach (Channel channel in sales.Channels) { foreach (Pay pay in channel.PayTypes) { try { HourlyRecordModel hourlyRecord = new HourlyRecordModel(); hourlyRecord.RestNum = sales.RestNumber; hourlyRecord.setBusinsessHourFromArray(sales.BusinessHour.ToArray()); hourlyRecord.Sales = Decimal.Parse(pay.Sales); hourlyRecord.DestCode = channel.DestCode; hourlyRecord.PayType = pay.PayType; if (hourlyRecord.propertiesNotNull()) { dataAccess.addHourlyRecord(hourlyRecord); } } catch (Exception ex) { } } } return(sales.RestNumber); }
/// <summary> /// Adds or updates an HourlyRecord in the DB /// </summary> /// <param name="record"></param> public void addHourlyRecord(HourlyRecordModel record) { DynamicParameters paramaters = new DynamicParameters(); paramaters.Add("@RestNum", record.RestNum); paramaters.Add("@BusinessHour", record.BusinessHour.ToString("yyyy-MM-dd HH:mm:ss.fff"), DbType.DateTime, ParameterDirection.Input); paramaters.Add("@Sales", record.Sales); paramaters.Add("@DestCode", record.DestCode); paramaters.Add("@PayType", record.PayType); paramaters.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); using (IDbConnection db = new SqlConnection(strConnectionString)) { db.Execute("LeeMiller.spInsertOrUpdate", paramaters, commandType: CommandType.StoredProcedure); int iIDReturned = paramaters.Get <int>("id"); } }