示例#1
0
        public IHttpActionResult PutStatus(int id, Status status)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != status.StatusId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public IHttpActionResult PutManufacturer(int id, Manufacturer manufacturer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != manufacturer.ManufacturerId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Create([Bind(Include = "ModelId,Name,ManufacturerCode,CategoryId,Description,Features,StatusId,ManufacturerId,ListPrice,ImageCollection,CategoryCustomData,ManufacturerCustomData,DateModified,DateCreated")] Model model)
        {
            if (ModelState.IsValid)
            {
                db.Models.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId     = new SelectList(db.Categories, "CategoryId", "Name", model.CategoryId);
            ViewBag.ManufacturerId = new SelectList(db.Manufacturers, "ManufacturerId", "Name", model.ManufacturerId);
            ViewBag.StatusId       = new SelectList(db.Status, "StatusId", "Name", model.StatusId);
            return(View(model));
        }
        public IHttpActionResult PutModel(int id, ModelDTO model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != model.ModelId)
            {
                return(BadRequest());
            }

            Model updateModel = new Model();

            updateModel.ModelId          = model.ModelId;
            updateModel.Name             = model.ModelName;
            updateModel.ManufacturerCode = model.ManufacturerCode;
            updateModel.CategoryId       = Int32.Parse(model.CategoryId);
            updateModel.Description      = model.Description;
            updateModel.StatusId         = Int32.Parse(model.StatusId);
            updateModel.ManufacturerId   = Int32.Parse(model.ManufacturerId);
            updateModel.ListPrice        = model.ListPrice;

            db.Models.Attach(updateModel);

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }