// Step 2 public ActionResult SaveWerkbriefAjax(string Products, string Projects, WerkbriefHoursTemp Model) { var model = new WerkbriefHoursTemp(); var userId = User.Identity.GetUserId(); var weeks = FetchWeeks(DateTime.Now.Year); ViewBag.Weeks = new SelectList(weeks); ViewBag.Products = new SelectList(db.Products.Where(p => p.UserId == userId && p.IsDeleted == false), "ProductID", "ProductName"); ViewBag.IdAddress = new SelectList(db.Addresses.Where(a => a.UserName == User.Identity.Name), "IdAddress", "StreetName"); ViewBag.Companies = new SelectList(db.Companies.Where(m => m.UserId == userId && m.IsDeleted == false), "CompanyID", "CompanyName"); ViewBag.Projects = new SelectList(db.Projects.Where(m => m.UserID == userId && m.IsDeleted == false), "ProjectID", "ProjectName"); // model.ProductInvoiceID = Int32.Parse(Products); var werkbriefTempId = db.WerkbriefTemps.Where(w => w.UserId == userId).OrderByDescending(w => w.DateCreated).FirstOrDefault().WerkbriefIDTemp; Model.TotalHours = GetTotalHours(Model).ToString(); Model.ProductID = Int32.Parse(Products); Model.WerkbriefIDTemp = werkbriefTempId; Model.ProjectID = Int32.Parse(Projects); db.WerkbriefHoursTemps.Add(Model); db.SaveChanges(); return(PartialView("~/Views/Shared/WerkbriefsPartials/_TabWerkbriefsPartial.cshtml", Model)); }
private decimal GetTotalHours(WerkbriefHoursTemp model) { var temp = decimal.Zero; var total = decimal.Zero; if (model.Monday != null && model.Monday.Contains('.')) { model.Monday = model.Monday.Replace('.', ','); } decimal.TryParse(model.Monday, out temp); total += temp; if (model.Tuesday != null && model.Tuesday.Contains('.')) { model.Tuesday = model.Tuesday.Replace('.', ','); } decimal.TryParse(model.Tuesday, out temp); total += temp; if (model.Wednesday != null && model.Wednesday.Contains('.')) { model.Wednesday = model.Wednesday.Replace('.', ','); } decimal.TryParse(model.Wednesday, out temp); total += temp; if (model.Thursday != null && model.Thursday.Contains('.')) { model.Thursday = model.Thursday.Replace('.', ','); } decimal.TryParse(model.Thursday, out temp); total += temp; if (model.Friday != null && model.Friday.Contains('.')) { model.Friday = model.Friday.Replace('.', ','); } decimal.TryParse(model.Friday, out temp); total += temp; if (model.Saturday != null && model.Saturday.Contains('.')) { model.Saturday = model.Saturday.Replace('.', ','); } decimal.TryParse(model.Saturday, out temp); total += temp; if (model.Sunday != null && model.Sunday.Contains('.')) { model.Sunday = model.Sunday.Replace('.', ','); } decimal.TryParse(model.Sunday, out temp); total += temp; return(total); }