Exemplo n.º 1
0
        public async Task <Center> Add(Center center)
        {
            db.Centers.Add(center);
            await db.SaveChangesAsync();

            return(center);
        }
Exemplo n.º 2
0
        public async Task <Trener> Add(Trener trener)
        {
            db.Treners.Add(trener);
            await db.SaveChangesAsync();

            return(trener);
        }
Exemplo n.º 3
0
        public async Task <Client> Add(Client client)
        {
            db.Clients.Add(client);
            await db.SaveChangesAsync();

            return(client);
        }
Exemplo n.º 4
0
        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"));
 }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 8
0
        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;
        }