public async Task <IHttpActionResult> PutContractor(Guid id, Contractor contractor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContractorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Date,ContractorId,NativeId,NodeId")] Link link)
        {
            if (ModelState.IsValid)
            {
                link.Id   = Guid.NewGuid();
                link.Date = DateTime.Now;
                db.Entry(link.Contractor).State = EntityState.Unchanged;
                db.Entry(link.Node).State       = EntityState.Unchanged;
                db.LinkSet.Add(link);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.ContractorId = new SelectList(db.ContractorSet, "Id", "Name", link.ContractorId);
            ViewBag.NodeId       = new SelectList(db.NodeSet, "Id", "Name", link.NodeId);
            return(View(link));
        }