public bool CreateMaintenance(MaintenanceCreate model) { Maintenance maintenance = new Maintenance(); int mileage = maintenance.OdomoterMileage; maintenance.MessageStr = MessagePopulateForMileage(mileage); maintenance.VehicleInformationStr = MessagePopulateForMileage(mileage); var entity = new Maintenance() { MaintenanceOwnerId = _maintenanceUserId, OdomoterMileage = model.OdomoterMileage, MaintenanceId = model.MaintenanceId, CreatedUtc = DateTimeOffset.Now, MessageId = model.MessageId, MessageStr = model.MessageStr, VehicleInformationId = model.VehicleInformationId, VehicleInformationStr = model.VehicleInformationStr, NoteId = model.NoteId }; using (var ctx = new ApplicationDbContext()) { ctx.Maintenances.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(MaintenanceCreate model) { if (!ModelState.IsValid) { return(View(model)); } var userId = Guid.Parse(User.Identity.GetUserId()); var service = new MaintenanceService(userId); service.CreateMaintenance(model); return(RedirectToAction("Index")); }
public async Task<ActionResult> Create(MaintenanceCreate model) { if (!ModelState.IsValid) { return View(model); } var service = EstablishMaintenanceService(); if (await service.CreateMaintenanceAsync(model)) { return RedirectToAction("Index"); } ModelState.AddModelError("", "Request does not meet the maintenance model specifications"); return View(model); }
public async Task <bool> CreateMaintenanceAsync(MaintenanceCreate model) { var entity = new Maintenance() { Category = model.Category, Description = model.Description, Active = model.Active, Permission = model.Permission, PropertyID = model.PropertyID, /*FK*/ }; _context.Maint.Add(entity); return(await _context.SaveChangesAsync() == 1); }