Пример #1
0
        public ActionResult <bool> UpdateItem(int id, [FromBody] Records entity)
        {
            try
            {
                var     c        = new vaccineContext();
                Records existing = c.Records.Where(p => p.Id == id).SingleOrDefault();
                //values
                existing.Citizen      = entity.Citizen == 0 ? existing.Citizen : entity.Citizen;
                existing.Vaccine      = entity.Vaccine == 0 ? existing.Vaccine : entity.Vaccine;
                existing.Province     = entity.Province == 0 ? existing.Province : entity.Province;
                existing.FirstVacDate = entity.FirstVacDate is null ? existing.FirstVacDate : entity.FirstVacDate;
                existing.LastVacDate  = entity.LastVacDate is null ? existing.LastVacDate : entity.LastVacDate;



                c.Update(existing);
                c.SaveChanges();

                return(true);
            }
            catch (System.Exception)
            {
                return(BadRequest());
            }
        }
Пример #2
0
        public ActionResult <bool> UpdateItem(int id, [FromBody] Citizens entity)
        {
            try
            {
                var      c        = new vaccineContext();
                Citizens existing = c.Citizens.Where(p => p.Id == id).SingleOrDefault();
                //values
                existing.FirstName = entity.FirstName is null ? existing.FirstName : entity.FirstName;
                existing.LastName  = entity.LastName is null ? existing.LastName : entity.LastName;
                existing.Phone     = entity.Phone is null ? existing.Phone : entity.Phone;
                existing.IdNumber  = entity.IdNumber is null ? existing.IdNumber : entity.IdNumber;
                existing.BirthDate = entity.BirthDate is null ? existing.BirthDate : entity.BirthDate;



                c.Update(existing);
                c.SaveChanges();

                return(true);
            }
            catch (System.Exception)
            {
                return(BadRequest());
            }
        }
Пример #3
0
        public ActionResult <Provinces> GetItem(int id)
        {
            Provinces entity = new vaccineContext().Provinces.Where(p => p.Id == id).SingleOrDefault();

            if (entity is null)
            {
                return(NotFound());
            }
            else
            {
                return(entity);
            }
        }
Пример #4
0
 public ActionResult <bool> DeleteItem(int id)
 {
     try
     {
         var c = new vaccineContext();
         c.Provinces.Remove(new vaccineContext().Provinces.Where(p => p.Id == id).SingleOrDefault());
         c.SaveChanges();
         return(true);
     }
     catch (System.Exception)
     {
         return(NotFound());
     }
 }
Пример #5
0
 public ActionResult <bool> CreateItem([FromBody] Provinces entity)
 {
     try
     {
         var c = new vaccineContext();
         c.Provinces.Add(entity);
         c.SaveChanges();
         return(true);
     }
     catch (System.Exception)
     {
         return(BadRequest());
     }
 }
Пример #6
0
        public ActionResult <bool> UpdateItem(int id, [FromBody] Provinces entity)
        {
            try
            {
                var       c        = new vaccineContext();
                Provinces existing = c.Provinces.Where(p => p.Id == id).SingleOrDefault();
                //values
                existing.Name = entity.Name is null ? existing.Name : entity.Name;

                c.Update(existing);
                c.SaveChanges();

                return(true);
            }
            catch (System.Exception)
            {
                return(BadRequest());
            }
        }