Пример #1
0
        public IHttpActionResult PostCareType(CareType careType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CareTypes.Add(careType);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CareTypeExists(careType.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = careType.Id }, careType));
        }
Пример #2
0
        public IHttpActionResult PutCareType(int id, CareType careType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != careType.Id)
            {
                return(BadRequest());
            }

            db.Entry(careType).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public IHttpActionResult GetCareType(int id)
        {
            CareType careType = db.CareTypes.Find(id);

            if (careType == null)
            {
                return(NotFound());
            }

            return(Ok(careType));
        }
Пример #4
0
        public IHttpActionResult DeleteCareType(int id)
        {
            CareType careType = db.CareTypes.Find(id);

            if (careType == null)
            {
                return(NotFound());
            }

            db.CareTypes.Remove(careType);
            db.SaveChanges();

            return(Ok(careType));
        }
Пример #5
0
        public async Task <int> SaveCareType(CareType careType)
        {
            if (careType.Id != 0)
            {
                _context.CareTypes.Update(careType);

                await _context.SaveChangesAsync();

                return(1);
            }
            else
            {
                await _context.CareTypes.AddAsync(careType);

                await _context.SaveChangesAsync();

                return(1);
            }
        }