public async Task <ActionResult <compagny> > PutCompagny(int id, compagny compagnyInput)
        {
            /// <summary>
            /// Edit the compagny information specified by its id
            /// </summary>
            if (id != compagnyInput.id)
            {
                return(BadRequest());
            }
            _context.Entry(compagnyInput).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompagnyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
Example #2
0
        public ActionResult Update(compagny c)
        {
            var compagnie = Repository.getCompagnyByID(c.id);

            compagnie.name   = c.name;
            compagnie.adress = c.adress;
            return(RedirectToAction("Details", new { id = c.id }));
        }
        public async Task <ActionResult <compagny> > PostCompagny(compagny compagnyBody)
        {
            /// <summary>
            /// Create a new compagny
            /// </summary>
            compagnyBody.createdAt = DateTime.Now;
            _context.compagnies.Add(compagnyBody);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCompagny), new { id = compagnyBody.id }, compagnyBody));
        }
Example #4
0
        public static List <compagny> GetCompgnies()
        {
            List <compagny> ls        = new List <compagny>();
            compagny        compagny1 = new compagny();

            compagny1.adress = "Paris";
            compagny1.id     = 1;
            compagny1.name   = "Orange";
            compagny compagny2 = new compagny();

            compagny2.adress = "Lyon";
            compagny2.id     = 2;
            compagny2.name   = "SamComp";
            compagny compagny3 = new compagny();

            compagny3.adress = "Nice";
            compagny3.id     = 3;
            compagny3.name   = "JulienComp";
            ls.Add(compagny1);
            ls.Add(compagny2);
            ls.Add(compagny3);
            return(ls);
        }