コード例 #1
0
        public async Task <ActionResult> Create([Bind(Include = "srvc_id,srvc_na,crt_dt")] tservice tservice)
        {
            if (ModelState.IsValid)
            {
                db.tservices.Add(tservice);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(tservice));
        }
コード例 #2
0
        // GET: tservices/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tservice tservice = await db.tservices.FindAsync(id);

            if (tservice == null)
            {
                return(HttpNotFound());
            }
            return(View(tservice));
        }
コード例 #3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            try
            {
                tservice tservice = await db.tservices.FindAsync(id);

                db.tservices.Remove(tservice);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMsg = "This record cannot be deleted.  It's value may be assigned to another table.";
                return(View("Delete"));
            }
        }
コード例 #4
0
        public async Task <ActionResult> Edit([Bind(Include = "srvc_id,srvc_na,crt_dt")] tservice tservice)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(tservice).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(tservice));
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMsg = "Unable to save your changes due to a data error.  Make sure there is not a duplicate record.";
                return(View(tservice));
            }
        }