public ActionResult AddRevenue(RevenueAddViewModel model) { if (ModelState.IsValid) { if (model.Revenue.RevenueId != 0) { //update var revenue = _revenueManager.Get(r => r.RevenueId == model.Revenue.RevenueId); revenue.RevenueName = model.Revenue.RevenueName; revenue.RevenueDescription = model.Revenue.RevenueDescription; revenue.RevenueAmount = model.Revenue.RevenueAmount; revenue.DateTime = model.Revenue.DateTime; revenue.CategoryId = model.Revenue.CategoryId; new RevenueManager().Update(revenue); } else { //add new RevenueManager().Add(model.Revenue); } } else { ViewBag.Message = "Model yanlış"; return(View()); } return(RedirectToAction("ListRevenue")); }
public async Task <IActionResult> Add([FromBody] RevenueAddViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // confirm user exists var userId = _userManager.GetUserId(HttpContext.User); if (userId == null) { return(BadRequest(Errors.AddErrorToModelState( "add_revenue_failure", "Unable to find a user for this revenue", ModelState))); } // confirm class exists var budget = _db.Budgets .FirstOrDefault(x => x.UserId == userId && x.Id == model.BudgetId); if (budget == null) { return(BadRequest(Errors.AddErrorToModelState( "add_revenue_failure", "Unable to find a budget for this revenue", ModelState))); } // add var newRecord = new Revenue { Description = model.Description, Amount = model.Amount, IsForever = model.IsForever, StartDate = model.StartDate, EndDate = model.EndDate, Frequency = model.Frequency, RepeatMon = model.RepeatMon, RepeatTue = model.RepeatTue, RepeatWed = model.RepeatWed, RepeatThu = model.RepeatThu, RepeatFri = model.RepeatFri, RepeatSat = model.RepeatSat, RepeatSun = model.RepeatSun, Budget = budget, BudgetId = budget.Id }; _db.Revenues.Add(newRecord); await _db.SaveChangesAsync(); return(new OkObjectResult(newRecord.Id)); }
public ActionResult AddRevenue(int id = 0) { var model = new RevenueAddViewModel(); CategoryManager categoryTypeManager = new CategoryManager(); var categories = categoryTypeManager.GetAll(); ViewBag.Categories = categories; if (id != 0) { var revenue = _revenueManager.Get(r => r.RevenueId == id); model.Revenue = revenue; } return(View(model)); }
public void AddRevenue_Test() { Revenue revenue = new Revenue() { ID = 1, Name = "TestRevenue", City = "TestCity", Street = "TestStreet" }; var mockContext = new Mock <IDbContext>(); var mockSet = new Mock <IDbSet <Revenue> >(); mockContext.Setup(m => m.Set <Revenue>()).Returns(mockSet.Object); RevenueAddViewModel cavm = new RevenueAddViewModel(mockContext.Object); cavm.Operation(revenue); mockSet.Verify(m => m.Add(It.IsAny <Revenue>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }