public async Task <IActionResult> Create([Bind("ServiceBookLogId,Date,Mileage,ServiceType,NextServiceDate,NextServiceMileage,CarWork,Details")] ServiceBookLog serviceBookLog) { var currentUserId = userManager.GetUserId(User); if (ModelState.IsValid) { _context.Add(serviceBookLog); await _context.SaveChangesAsync(); int?id = int.Parse(RouteData.Values["id"].ToString()); if (id != null) { var serviceBooks = new ServiceBook[] { new ServiceBook { CarId = (int)id, ServiceBookLogId = serviceBookLog.ServiceBookLogId } }; foreach (ServiceBook serviceBook in serviceBooks) { _context.ServiceBooks.Add(serviceBook); } await _context.SaveChangesAsync(); } return(RedirectToAction("Details", "Cars", new { id })); } return(View(serviceBookLog)); }
public async Task <IActionResult> Create(Car car, IFormFile image) { var currentUserId = userManager.GetUserId(User); if (ModelState.IsValid) { car.UserId = currentUserId; if (image != null && image.Length > 0) { var fileName = string.Empty; if (car.UserId != null) { fileName = $"{car.Brand}_{car.Model}_{car.UserId}.{image.FileName.Split('.').Last()}"; } else { fileName = $"{car.Brand}_{car.Model}_null.{image.FileName.Split('.').Last()}"; } var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\carimages", fileName); using (var fileSteam = new FileStream(filePath, FileMode.Create)) { await image.CopyToAsync(fileSteam); } car.Image = fileName; } _context.Add(car); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(car)); }
public void SaveHistory(History objectModel, long userId) { var objectTypeName = objectModel.GetType().Name; var objectTypeId = context.Set <ObjectType>().Where(x => x.Name == objectTypeName).FirstOrDefault().Id; var _object = new Models.Object() { CreatedById = userId, ModifiedById = userId, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, ObjectTypeId = objectTypeId }; context.Add(_object); context.SaveChanges(); context.Add <History>(objectModel); context.SaveChanges(); }
public void Save(T objectModel, long userId, long houseId, long?targetObjectId) { var objectTypeName = objectModel.GetType().Name; var objectTypeId = context.Set <ObjectType>().Where(x => x.Name == objectTypeName).FirstOrDefault().Id; var _object = new APPartment.Models.Object() { CreatedById = userId, ModifiedById = userId, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, ObjectTypeId = objectTypeId }; context.Add(_object); context.SaveChanges(); objectModel.ObjectId = _object.ObjectId; Task.Run(async() => await this.SaveChangesAsync(true, houseId, userId, targetObjectId, _object.ObjectId, objectModel, ContextExecutionTypes.Create)).Wait(); }
public void Save(T objectModel, long userId, long?targetObjectId, long houseId) { var objectTypeName = objectModel.GetType().Name; var objectTypeId = context.Set <ObjectType>().Where(x => x.Name == objectTypeName).FirstOrDefault().Id; var _object = new Models.Object() { CreatedById = userId, ModifiedById = userId, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, ObjectTypeId = objectTypeId }; context.Add(_object); context.SaveChanges(); historyContext.PopulateHistory((int)HistoryFunctionTypes.Create, objectModel, _object, userId, targetObjectId, houseId); objectModel.ObjectId = _object.ObjectId; context.Add <T>(objectModel); context.SaveChanges(); }
public async void UpdateDatabase() { var result = new ValuesModel(); foreach (var item in MicrocontrollerMap.IpMapId) { string url = item.Value; int id = item.Key; if (!String.IsNullOrEmpty(url)) { result.MicrocontrollerID = id; result.Temperature = GetTemperature(url); result.DoorOpen = GetDoorOpen(url); result.Dust = GetDust(url); result.DateTime = DateTime.Now; result.Humidity = GetHumidity(url); result.Power = GetPower(url); _context.Add(result); await _context.SaveChangesAsync(); } } }