private EstimatesViewModel GetEstimatesViewModel(string projectId) { var estimatesViewModel = new EstimatesViewModel(); if (!_cacheManager.KeyExist(projectId)) { return(null); } var estimates = _cacheManager.Get <Estimates>(projectId); estimatesViewModel.IsShow = estimates.IsShow; estimatesViewModel.AveragePoint = estimates.AveragePoint; if (estimates.EstimateList.Count <= 0) { return(estimatesViewModel); } foreach (var item in estimates.EstimateList) { var user = _userLogic.Get(item.UserId); estimatesViewModel.EstimateViewModel.Add(new EstimateViewModel { ProjectId = item.ProjectId, SelectedPoker = item.SelectedPoker, UserImage = user.ImagePath, UserName = user.Name, UserId = user.Id.ToString(), Email = user.Email }); } return(estimatesViewModel); }
public ActionResult PreviewEstimate(Estimate estimate) { // Instantiate the view model we will use in this view EstimatesViewModel ViewModel = new EstimatesViewModel(); // Make sure the id is for a valid design order DesignOrder DOrder = db.DesignOrders.Find(estimate.DesignOrderSID); if (DOrder == null) { return(RedirectToAction("DesignOrders")); } else { // Store the design order in the view model ViewModel.DesignOrders = new List <DesignOrder> { DOrder }; } // Get other needed models for populating drop down lists etc ViewModel.StressWorkTypes = db.StressWorkTypes.ToList(); ViewModel.ToolTypes = db.ToolTypes.ToList(); ViewModel.FamilyClasses = db.FamilyClasses.ToList(); ViewModel.AppUsers = db.AppUsers.ToList(); ViewModel.Statistics = db.Statistics.ToList(); ViewModel.ComplexityLevels = db.ComplexityLevels.ToList(); ViewModel.Estimates = new List <Estimate> { estimate }; return(View(ViewModel)); }
public void DisplayData(EstimatesResponseModel response) { EstimatesViewModel estimatesViewModel = new EstimatesViewModel(); estimatesViewModel.AveragePriceOfHouses = response.AverageHousePrice.ToString(); _frontEnd.UpdateAveragePriceField(estimatesViewModel); }
// GET: Estimates/Create public ActionResult CreateOrder() { // Initialize the view model EstimatesViewModel ViewModel = new EstimatesViewModel(); // Add the tool types to the view model (for drop down) ViewModel.DesignOrders = new List <DesignOrder> { new DesignOrder() }; ViewModel.ToolTypes = db.ToolTypes.ToList(); // Return the view return(View(ViewModel)); }
public ActionResult CreateOrder([Bind(Include = "DesignOrderSID,DescriptiveName,DesignOrderNumber,ToolTypeID,PartNumber,Completed,ActualHours")] DesignOrder DOrder) { if (ModelState.IsValid) { // check uniqueness // aka if the db has a design order with that design order number already if (db.DesignOrders.Where(v => v.DesignOrderNumber == DOrder.DesignOrderNumber).FirstOrDefault() != null) { ModelState.AddModelError("DOrderExists", "<span class='text-danger'> Design Order already exists. Click <a href=\"List/" + db.DesignOrders.Where(v => v.DesignOrderNumber == DOrder.DesignOrderNumber).FirstOrDefault().DesignOrderSID + "\">here</a> to view it.</span>"); // Initialize the view model EstimatesViewModel ViewModel = new EstimatesViewModel(); // Add the tool types to the view model (for drop down) ViewModel.DesignOrders = new List <DesignOrder> { new DesignOrder() }; ViewModel.ToolTypes = db.ToolTypes.ToList(); // Return the view return(View(ViewModel)); } else { db.DesignOrders.Add(DOrder); DOrder.CreatedDate = DateTime.Today; DOrder.IsDeleted = false; DOrder.CreatedByUserID = db.AppUsers.Single(u => u.UserEmail == User.Identity.Name).AppUserID; db.SaveChanges(); if (Request.Form["saveAndEstimate"] != null) { return(RedirectToAction("Create", new { id = DOrder.DesignOrderSID })); } return(RedirectToAction("DesignOrders")); } } return(View(DOrder)); }
public ActionResult EditOrder([Bind(Include = "DesignOrderSID,DescriptiveName,DesignOrderNumber,ToolTypeID,PartNumber,IsCompleted,ActualHours")] DesignOrder DOrder) { if (ModelState.IsValid) { DesignOrder NewOrder = db.DesignOrders.Find(DOrder.DesignOrderSID); NewOrder.DesignOrderNumber = DOrder.DesignOrderNumber; NewOrder.DescriptiveName = DOrder.DescriptiveName; NewOrder.ToolTypeID = DOrder.ToolTypeID; NewOrder.PartNumber = DOrder.PartNumber; NewOrder.IsCompleted = DOrder.IsCompleted; NewOrder.ActualHours = DOrder.ActualHours; db.Entry(NewOrder).State = EntityState.Modified; NewOrder.UpdatedDate = DateTime.Today; db.SaveChanges(); return(RedirectToAction("DesignOrders")); } // Initialize view model EstimatesViewModel ViewModel = new EstimatesViewModel(); // Redirect if the ID is not a valid design order id if (DOrder == null) { return(RedirectToAction("DesignOrders", "Estimates")); } // Put needed elements on the view model ViewModel.ToolTypes = db.ToolTypes.ToList(); ViewModel.DesignOrders = new List <DesignOrder> { DOrder }; return(View(ViewModel)); }
// GET Edit a design Order public ActionResult EditOrder(int?id) { // Initialize view model EstimatesViewModel ViewModel = new EstimatesViewModel(); // Get the design order from the submitted ID DesignOrder DOrder = db.DesignOrders.Find(id); // Redirect if the ID is not a valid design order id if (DOrder == null) { return(RedirectToAction("DesignOrders", "Estimates")); } // Put needed elements on the view model ViewModel.ToolTypes = db.ToolTypes.ToList(); ViewModel.DesignOrders = new List <DesignOrder> { DOrder }; // Return the view return(View(ViewModel)); }
// Design Orders Action public ActionResult DesignOrders() { // Get all Design Orders IQueryable <DesignOrder> DesignOrderLINQ = db.DesignOrders; List <DesignOrder> DesignOrders = DesignOrderLINQ.Where(d => d.IsDeleted == false).ToList(); // Get only users who have created design orders List <AppUser> AppUsers = db.AppUsers.Where(u => DesignOrderLINQ.Select(d => d.CreatedByUserID).Contains(u.AppUserID)).ToList(); // Get the latest estimates for those design orders List <Estimate> Estimates = db.Estimates.Where(e => e.IsLatestEstimate == true).ToList(); // Add models to view model EstimatesViewModel ViewModel = new EstimatesViewModel(); ViewModel.DesignOrders = DesignOrders; ViewModel.AppUsers = AppUsers; ViewModel.Estimates = Estimates; ViewModel.ToolTypes = db.ToolTypes.ToList(); // Return the view return(View(ViewModel)); }
// List Action /* * Lists the estimates made for one particular design order */ public ActionResult List(int?id) { // Pass the estimates to the view that match the selected design order ViewBag.DesignOrderSID = id; if (id == null) { // Redirect to the design orders page if they haven't selected a design order yet return(RedirectToAction("DesignOrders", "Estimates")); } else { // Get the Design Orders IQueryable <DesignOrder> DesignOrderLINQ = db.DesignOrders; List <DesignOrder> DesignOrders = DesignOrderLINQ.Where(d => d.DesignOrderSID == id).ToList(); // Get all users List <AppUser> AppUsers = db.AppUsers.ToList(); int DesignOrderSID = DesignOrders.First().DesignOrderSID; // Get all latest estimates for those design orders List <Estimate> Estimates = db.Estimates.Where( e => e.DesignOrderSID == DesignOrderSID && e.IsDeleted == false ).OrderByDescending(e => e.CreatedDate).ToList(); EstimatesViewModel ViewModel = new EstimatesViewModel(); ViewModel.DesignOrders = DesignOrders; ViewModel.AppUsers = AppUsers; ViewModel.Estimates = Estimates; ViewModel.ToolTypes = db.ToolTypes.ToList(); // Get all estimates for the selected design order return(View(ViewModel)); } }
// GET: Estimates/Details/5 public ActionResult Details(int?id) { if (id == null) { return(RedirectToAction("DesignOrders")); } Estimate estimate = db.Estimates.Find(id); if (estimate == null) { return(HttpNotFound()); } EstimatesViewModel ViewModel = new EstimatesViewModel(); ViewModel.Estimates = new List <Estimate>(); ViewModel.Estimates.Add(estimate); ViewModel.AppUsers = db.AppUsers.ToList(); ViewModel.ToolTypes = db.ToolTypes.ToList(); ViewModel.DesignOrders = db.DesignOrders.ToList(); ViewModel.FamilyClasses = db.FamilyClasses.ToList(); ViewModel.StressWorkTypes = db.StressWorkTypes.ToList(); ViewModel.Statistics = db.Statistics.ToList(); // Also get the id of the latest estimate for this view model ViewBag.LatestEstimateID = null; Estimate LatestEstimate = db.Estimates.Where(e => e.DesignOrderSID == estimate.DesignOrderSID && e.IsLatestEstimate == true).FirstOrDefault(); if (LatestEstimate != null) { ViewBag.LatestEstimateID = LatestEstimate.EstimateID; } // Return the view model to the view return(View(ViewModel)); }
// GET: Estimates/Create public ActionResult Create(int?id) { // Instantiate the view model we will use in this view EstimatesViewModel ViewModel = new EstimatesViewModel(); // Some unused code for checking errors on hidden form elements //IEnumerable<ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); //ViewBag.Errors = allErrors; // Check if they have submitted a design order id if (id == null) { return(RedirectToAction("DesignOrders")); } // Make sure the id is for a valid design order DesignOrder DOrder = db.DesignOrders.Find(id); if (DOrder == null) { return(RedirectToAction("DesignOrders")); } else { // Store the design order in the view model ViewModel.DesignOrders = new List <DesignOrder> { DOrder }; } // Get other needed models for populating drop down lists etc ViewModel.StressWorkTypes = db.StressWorkTypes.ToList(); ViewModel.ToolTypes = db.ToolTypes.ToList(); ViewModel.FamilyClasses = db.FamilyClasses.ToList(); ViewModel.AppUsers = db.AppUsers.ToList(); ViewModel.Statistics = db.Statistics.ToList(); ViewModel.ComplexityLevels = db.ComplexityLevels.ToList(); // Get the latest estimate for this design order, if any Estimate LatestEstimate = db.Estimates .Where(e => e.DesignOrderSID == DOrder.DesignOrderSID) .Where(e => e.IsLatestEstimate == true) .ToList().FirstOrDefault(); // Create an empty estimate and set the fields we already know Estimate est = new Estimate(); est.DesignOrderSID = DOrder.DesignOrderSID; // If there aren't any previous estimates, set a default value for "reason for estimate change" to "initial estimate" if (LatestEstimate == null) { est.ReasonForEstimateChange = "Initial Estimate"; } else { // Auto-fill this estimate with values from the latest estimate est.NeedsSurfacing = LatestEstimate.NeedsSurfacing; est.IsStressIncluded = LatestEstimate.IsStressIncluded; est.StressWorkTypeID = LatestEstimate.StressWorkTypeID; est.ComplexityLevel = LatestEstimate.ComplexityLevel; est.EngineeringReleased = LatestEstimate.EngineeringReleased; est.FamilyClassID = LatestEstimate.FamilyClassID; } // Return everything to the view ViewModel.Estimates = new List <Estimate> { est }; return(View(ViewModel)); }
public void UpdateAveragePriceField(EstimatesViewModel estimatesViewModel) { textBox_AvaragePricePerSquareMeter.Text = estimatesViewModel.AveragePriceOfHouses; }