Пример #1
0
        public IHttpActionResult PostTargetCompany(TargetCompany targetCompany)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TargetCompanies.Add(targetCompany);
            if (db.SaveChanges() > 0)
            {
                return(Ok());
            }
            else
            {
                return(InternalServerError());
            }
        }
Пример #2
0
        public IHttpActionResult PutTargetCompany(int id, TargetCompany targetCompany)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != targetCompany.Id)
            {
                return(BadRequest());
            }
            // TargetCompany Entity
            db.Entry(targetCompany).State = EntityState.Modified;
            // Contact Entities from TargetCompany
            targetCompany.TargetCompanyContacts.ToList().ForEach(contact =>
            {
                db.Entry(contact).State = EntityState.Modified;
            });
            // FinancePeriod Entities from TargetCompany
            targetCompany.TargetCompanyFinancialPeriods.ToList().ForEach(financePeriod =>
            {
                db.Entry(financePeriod).State = EntityState.Modified;
            });

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
 public IHttpActionResult DeleteTargetCompany([FromUri] int[] id)
 {
     // If one of the keys does not exist return notfound result
     foreach (var key in id)
     {
         if (!TargetCompanyExists(key))
         {
             return(NotFound());
         }
     }
     foreach (var key in id)
     {
         TargetCompany targetCompany = db.TargetCompanies
                                       .Include(c => c.TargetCompanyContacts.Select(cr => cr.TargetCompany))
                                       .Include(f => f.TargetCompanyFinancialPeriods.Select(cf => cf.TargetCompany))
                                       .Where(x => x.Id == key).FirstOrDefault();
         db.TargetCompanies.Remove(targetCompany);
     }
     db.SaveChanges();
     return(Ok());
 }