public IHttpActionResult PutBook(int id, Book book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != book.Id) { return(BadRequest()); } db.Entry(book).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "ListItemId,ItemName,PriorityId,Amount")] ListItemModel listItemModel) { if (ModelState.IsValid) { db.ListItem.Add(listItemModel); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PriorityId = new SelectList(db.Priority, "PriorityId", "Description", listItemModel.PriorityId); return(View(listItemModel)); }
public void Adicionar(T entity) { try { _db.Add(entity); _context.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Create([Bind(Include = "SummaryId,SummaryName,UpdatedAmount,PendingAmount,TotalAmount,CreationDate,LastModificationDate,PeriodId")] SummaryModel summaryModel) { if (ModelState.IsValid) { summaryModel.CreationDate = DateTime.Now; summaryModel.LastModificationDate = DateTime.Now; db.Summary.Add(summaryModel); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PeriodId = new SelectList(db.Period, "PeriodId", "PeriodName", summaryModel.PeriodId); return(View(summaryModel)); }
public ActionResult Create([Bind(Include = "ConceptId,ConceptName,Amount,EsEgreso,Payd,Prepayment,AmountPayable,PayDate,CreationDate,LastModificationDate,SummaryId")] ConceptModel conceptModel) { if (ModelState.IsValid) { conceptModel.CreationDate = DateTime.Now; conceptModel.LastModificationDate = DateTime.Now; db.Concept.Add(conceptModel); db.SaveChanges(); concepts.UpdateAmountsSummary(conceptModel); return(RedirectToAction("Index", new { SummaryId = conceptModel.SummaryId })); } ViewBag.SummaryId = new SelectList(db.Summary, "SummaryId", "SummaryName", conceptModel.SummaryId); return(View(conceptModel)); }
static void Main(string[] args) { using (var file = new FileStream(ConfigurationManager.AppSettings["sourceFile"], FileMode.Open)) using (var db = new DataContext.DataContext()) { var data = CsvReader.ReadFromStream(file); foreach (var line in data) { Console.WriteLine(@"Adding: {0}, {1}", line[0], line[1]); db.Items.Add(new DataContext.Models.Entry { Title = line[0], Value = int.Parse(line[1]) }); } db.SaveChanges(); } }
public void UpdateAmountsSummary(ConceptModel concept) { using (DataContext.DataContext db = new DataContext.DataContext()) { SummaryModel summary = db.Summary.Where(t => t.SummaryId == concept.SummaryId).FirstOrDefault(); if (summary != null) { decimal?ConceptsPayd = 0; decimal?Prepayment = 0; summary.TotalIncome = db.Concept.Where(t => !t.EsEgreso).Sum(t => (decimal?)t.Amount); summary.TotalOutcome = db.Concept.Where(t => t.EsEgreso).Sum(t => (decimal?)t.Amount); //summary.TotalAmount = db.Concept.Where(t => t.SummaryId == summary.SummaryId && t.EsEgreso).Sum(t => (decimal?)t.Amount); ConceptsPayd = db.Concept.Where(t => t.SummaryId == summary.SummaryId && t.Payd && t.EsEgreso).Sum(t => (decimal?)t.Amount) ?? (decimal)0; Prepayment = db.Concept.Where(t => t.SummaryId == summary.SummaryId && !t.Payd && t.Prepayment > 0).Sum(t => (decimal?)t.Prepayment) ?? (decimal)0; summary.ConceptsPayd = ConceptsPayd.Value + Prepayment; db.SaveChanges(); } } }
public void Save() { db.SaveChanges(); }