public async Task <int> AddExpectedNeeds(ExpectedNeeds expected) { if (_db != null) { await _db.ExpectedNeeds.AddAsync(expected); await _db.SaveChangesAsync(); return(1); } return(0); }
public async Task <int> UpdateExpectedNeeds(int id, ExpectedNeeds expected) { if (_db != null) { ExpectedNeeds existItem = _db.ExpectedNeeds.Where(f => f.IdexpectedNeeds == id).FirstOrDefault(); if (existItem != null) { existItem.ExpectedQuantity = expected.ExpectedQuantity; existItem.Date = expected.Date; existItem.ProductId = expected.ProductId; _db.ExpectedNeeds.Update(existItem); await _db.SaveChangesAsync(); return(1); } } return(0); }
public async Task <IActionResult> UpdateExpectedNeeds(ExpectedNeeds expected, int id) { try { var result = await _needs.UpdateExpectedNeeds(id, expected); if (result != 0) { var Response = new ResponseViewModel(true, HttpStatusCode.OK, "SUCCESS", result); return(Ok(Response)); } else { var Response = new ResponseViewModel(false, HttpStatusCode.NoContent, "failed", null); return(Ok(Response)); } } catch { return(BadRequest()); } }
public async Task <List <double> > GetExpectedNeedsByType(int type, string period, DateTime start, DateTime end) { try { if (period == "daily") { //Define list of Expected needs each day to store the result List <Double> result = new List <double>(); TimeSpan diff = end.Subtract(start); for (var day = start.Date; day <= end.Date; day = day.AddDays(1)) { //to store the full Expected needs Double value = 0; string test = day.ToString("yyyy-MM-dd"); //return list of Id expectedneeds in each day List <int> expectedneeds = _db.ExpectedNeeds.Where(x => x.Date.ToString() == test && x.ProductId == type) .Select(x => x.IdexpectedNeeds).ToList(); for (int j = 0; j < expectedneeds.Count; j++) { ExpectedNeeds subResult = await GetDailyExpectedNeeds(expectedneeds[j]); value += Convert.ToDouble(subResult.ExpectedQuantity); } result.Add(value); } return(result); } else if (period == "monthly") { //Define list of Actual Needs to store the result List <Double> result = new List <double>(); TimeSpan diff = end.Subtract(start); for (var month = start.Month; month <= end.Month; month++) { //to store the all actual needs Double value = 0; //return list of id actual needs in each day List <int> expectedneeds = await _db.ExpectedNeeds.Where(x => x.Date.Value.Month == month && x.ProductId == type) .Select(x => x.IdexpectedNeeds).ToListAsync(); for (int j = 0; j < expectedneeds.Count; j++) { ExpectedNeeds subResult = await GetDailyExpectedNeeds(expectedneeds[j]); value += Convert.ToDouble(subResult.ExpectedQuantity); } result.Add(value); } return(result); } else if (period == "annual") { //Define list of Actual Needs to store the result List <Double> result = new List <double>(); System.TimeSpan diff = end.Subtract(start); for (var year = start.Year; year <= end.Year; year++) { //to store the full Actual Needs Double value = 0; //return list of id_Actual Needs in each day List <int> expectedneeds = await _db.ExpectedNeeds.Where(x => x.Date.Value.Year == year && x.ProductId == type) .Select(x => x.IdexpectedNeeds).ToListAsync(); for (int j = 0; j < expectedneeds.Count; j++) { ExpectedNeeds subResult = await GetDailyExpectedNeeds(expectedneeds[j]); value += Convert.ToDouble(subResult.ExpectedQuantity); } result.Add(value); } return(result); } return(null); } catch (Exception) { return(null); } }