public IActionResult Edit(Guid id) { // Getting uniqueName var uniqueName = HttpContext.User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value; // Getting the selected fiscal year var metricToBeViewed = Util.ConnectToRemoteService <MetricViewModel>(HttpMethod.Get, Util.KanbanURL + "api/metric/getmetricbyid?id=" + id, uniqueName, "").Result; if (metricToBeViewed != null) { var metric = new MetricViewModel() { MetricID = metricToBeViewed.MetricID, MetricCategory = metricToBeViewed.MetricCategory, MetricName = metricToBeViewed.MetricName, Description = metricToBeViewed.Description, FiscalYearID = metricToBeViewed.FiscalYearID, TextualFiscalYear = metricToBeViewed.TextualFiscalYear, FullNumericFiscalYear = metricToBeViewed.FullNumericFiscalYear }; return(View(metric)); } else { ViewBag.Message = "The system has not found the metric."; return(View("Error")); } }
// Update metric data based on ID public bool EditMetricByID(MetricViewModel metric) { //var metricToBeUpdated = (from m in _context.Metrics // where m.MetricID == metric.MetricID // select m).First(); //var fyToBeIncluded = (from fy in _context.FiscalYears // where fy.FiscalYearID == metric.FiscalYearID // select fy).First(); //if (metricToBeUpdated != null) //{ // // Update informations of object // metricToBeUpdated.MetricName = metric.MetricName; // metricToBeUpdated.MetricCategory = metric.MetricCategory; // metricToBeUpdated.Description = metric.Description; // metricToBeUpdated.FiscalYear = fyToBeIncluded; // var response = _context.SaveChanges(); // return true; //} //else //{ // return false; //} throw new NotImplementedException(); }
// Adds a new metric to the system. public bool AddNewMetric(MetricViewModel metric) { var fy = _context.FiscalYears.FirstOrDefault(f => f.FiscalYearID == metric.FiscalYearID); var metricToBeSaved = new Metric() { MetricID = metric.MetricID, MetricCategory = metric.MetricCategory, MetricName = metric.MetricName, Description = metric.Description, FiscalYear = fy }; _context.Metrics.Add(metricToBeSaved); var response = _context.SaveChanges(); if (response > 0) { return(true); } else { return(false); } }
// Update metric data based on ID public bool EditMetricByID(MetricViewModel metric) { var metricToBeUpdated = (from m in _context.Metrics where m.MetricID == metric.MetricID select m).First(); var fyToBeIncluded = (from fy in _context.FiscalYears where fy.FiscalYearID == metric.FiscalYearID select fy).First(); if (metricToBeUpdated != null) { // Update informations of object metricToBeUpdated.MetricName = metric.MetricName; metricToBeUpdated.MetricCategory = metric.MetricCategory; metricToBeUpdated.Description = metric.Description; metricToBeUpdated.FiscalYear = fyToBeIncluded; var response = _context.SaveChanges(); return(true); } else { return(false); } }
public async Task <JsonResult> EditMetric(MetricViewModel metric) { if (ModelState.IsValid) { Metric _metric = AutoMapperConfiguration.Mapper.Map <Metric>(metric); bool result = await _metricService.EditMetric(_metric); return(Json(result, JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public async Task <HttpResponseMessage> EditMetric(MetricViewModel metric) { if (metric == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } var uniqueName = HttpContext.User.Claims.First(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value; var responseAboutUpdate = await Util.ConnectToRemoteService(HttpMethod.Put, Util.KanbanURL + "api/metric/editmetricbyid", uniqueName, "", metric); if (responseAboutUpdate.IsSuccessStatusCode) { return(new HttpResponseMessage(HttpStatusCode.OK)); } else { return(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } }
// maps all metric information by looping through and calculating based on end date private MetricViewModel BananaMapper(List <Bananas_Purchased> bananas_Purchaseds, DateTime endDate) { var metricModel = new MetricViewModel(); var sellPrice = Convert.ToDouble(ConfigurationManager.AppSettings["sell"]); var purchasePrice = Convert.ToDouble(ConfigurationManager.AppSettings["purchase"]); foreach (var banana in bananas_Purchaseds) { metricModel.Bananas += banana.Bananas; if (banana.Bananas != banana.Sold && banana.ExpirationDate <= endDate) { metricModel.BananasExpired += banana.Bananas - banana.Sold; } metricModel.BananasSold += banana.Sold; metricModel.ProfitLoss = (metricModel.BananasSold * sellPrice - metricModel.Bananas * purchasePrice).ToString("C"); } return(metricModel); }
// Adds a new metric to the system. public bool AddNewMetric(MetricViewModel metric) { var currentFiscalYear = metric.FiscalYearID; var fy = fiscalYearRepository.GetFiscalYearByID(currentFiscalYear); var model = new Metric() { _id = metric.MetricID.ToString(), metricCategory = metric.MetricCategory, metricName = metric.MetricName, description = metric.Description, FiscalYear = new FiscalYear() { _id = fy.FiscalYearID.ToString(), fullNumericFiscalYear = fy.FullNumericFiscalYearMain, textualFiscalYear = fy.TextualFiscalYearMain } }; _context.Metrics.InsertOne(model); return(true); }