public IActionResult AddDisk([FromBody] AddDiskModel model) { var timing = userService.AddDisk(model); if (timing == 0) { return(BadRequest(new { Message = "Something went wrong." })); } return(Ok(new { SecondsElapsed = timing })); }
public double AddDisk(AddDiskModel model) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Disk newDisk = new Disk { DiskId = model.Id, DiskSize = model.Capacity, Device = context.Devices.First(device => device.DeviceId == model.Device), OperationState = context.OperationStates.First(opState => opState.DisplayValue == "Online") }; context.Disks.Add(newDisk); context.SaveChanges(); stopWatch.Stop(); return(stopWatch.Elapsed.TotalSeconds); }