예제 #1
0
        public IHttpActionResult PutKabinets(int id, KabinetsViewModel kabinetsModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var kabinets = db.Kabinets.FirstOrDefault(x => x.KabinetaID == kabinetsModel.KabinetaID);

            if (id != kabinets.KabinetaID)
            {
                return(BadRequest());
            }

            kabinets.InventaraID          = kabinetsModel.InventaraID;
            kabinets.Inventars            = db.Inventars.FirstOrDefault(x => x.InventaraID == kabinetsModel.InventaraID);
            kabinets.IericesID            = kabinetsModel.IericesID;
            kabinets.ElektroniskasIerices = db.ElektroniskasIerices.FirstOrDefault(x => x.IericesID == kabinetsModel.IericesID);
            kabinets.AtbildigaisID        = kabinetsModel.AtbildigaisID;
            kabinets.Atbildigais1         = db.Atbildigais.FirstOrDefault(x => x.AtbildigaisID == kabinetsModel.AtbildigaisID);
            db.Entry(kabinets).State      = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KabinetsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public IHttpActionResult PostKabinets(KabinetsViewModel kabinetsModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var kabinets = new KabinetsWolverine
            {
                InventaraID          = kabinetsModel.InventaraID,
                Inventars            = db.Inventars.FirstOrDefault(x => x.InventaraID == kabinetsModel.InventaraID),
                IericesID            = kabinetsModel.IericesID,
                ElektroniskasIerices = db.ElektroniskasIerices.FirstOrDefault(x => x.IericesID == kabinetsModel.IericesID),
                AtbildigaisID        = kabinetsModel.AtbildigaisID,
                Atbildigais1         = db.Atbildigais.FirstOrDefault(x => x.AtbildigaisID == kabinetsModel.AtbildigaisID)
            };

            db.Kabinets.Add(kabinets);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (KabinetsExists(kabinets.KabinetaID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DeadpoolApi-Kabinets", new { id = kabinets.KabinetaID }, kabinets));
        }