public async Task <Center> Add(Center center) { db.Centers.Add(center); await db.SaveChangesAsync(); return(center); }
public async Task <Trener> Add(Trener trener) { db.Treners.Add(trener); await db.SaveChangesAsync(); return(trener); }
public async Task <Client> Add(Client client) { db.Clients.Add(client); await db.SaveChangesAsync(); return(client); }
public async Task <ActionResult <Center> > PostCenter(Center c) { _context.Centers.Add(c); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCenter), new { id = c.Id }, c)); }
public async Task <IActionResult> Edit(Equipment equipment) { if (ModelState.IsValid) { try { _context.Update(equipment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } } return(RedirectToAction("Store")); }
public async Task <bool> Create(E entity) { try { await _dbSet.AddAsync(entity); await _centerContext.SaveChangesAsync(); } catch (Exception e) { return(false); throw e; } return(true); }
public async Task <IActionResult> Add([Bind("EquipmentId", "Number", "Reason")] Invoice invoice) { try { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(HttpContext.User); invoice.WorkerId = user.Id; invoice.Date = DateTime.Now; _context.Add(invoice); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } } catch (DbUpdateException /* ex */) { //Log the error ModelState.AddModelError("", "无法保存更改,重试或联系系统管理员."); } return(View(invoice)); }
public CenterController(CenterContext context) { if (context.Centers.Count() == 0) { var file = System.IO.File.ReadAllText(@"C:\Users\dloconte\Downloads\RESTapp\HackathonREST\HackathonREST\App-Data\centers.json"); var jObject = JObject.Parse(file); if (jObject != null) { JArray centersArray = (JArray)jObject["Centers"]; JArray centerTypesArray = (JArray)jObject["CenterTypes"]; List <String> centerTypes = new List <string>(); foreach (var type in centerTypesArray) { var centerType = type["Value"]; centerTypes.Add(centerType.ToString()); } foreach (var center in centersArray) { Center c = new Center(); c.Id = (int)center["Id"]; c.Name = center["Name"].ToString(); c.StreetAddress = center["StreetAddress"].ToString(); c.CenterTypeId = (int)center["CenterTypeId"]; for (int i = 1; i <= centerTypesArray.Count; i++) { if ((int)center["CenterTypeId"] == i) { c.CenterTypeValue = centerTypes[i - 1]; } } context.Centers.Add(c); } } context.SaveChangesAsync(); } _context = context; }