DBPOLLDemo.Models.pollObjectModel.createObject C# (CSharp) Метод

createObject() публичный Метод

public createObject ( int obtype, String attribute, int pollid ) : void
obtype int
attribute String
pollid int
Результат void
        public void createObject(int obtype, String attribute, int pollid)
        {
            try
            {
                POLL_OBJECTS_DFLT po = new POLL_OBJECTS_DFLT();

                po.O_ID = obtype;
                po.ATTRIBUTE = attribute;
                po.P_ID = pollid;

                dbpollContext.AddToPOLL_OBJECTS_DFLT(po);

                int status = dbpollContext.SaveChanges();
            }
            catch (Exception e)
            {
                throw (e);
            }
        }

Usage Example

Пример #1
0
        public ActionResult Create(int obtype, String attribute, int pollid)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_CREATOR)
            {
                return RedirectToAction("Invalid", "Home");
            }

            ViewData["pollid"] = pollid;

            pollObjectModel ob = new pollObjectModel();

            if (ob.getObject(obtype, pollid).obid != -1)
            {
                ViewData["created"] = "This object already exists.";
                return View();
            }

            try
            {
                switch (obtype)
                {
                    case 1:
                        ViewData["created"] = "Added a Countdown Timer";
                        break;
                    case 2:
                        ViewData["created"] = "Added a Response Counter";
                        break;
                    case 3:
                        ViewData["created"] = "Added a Correct Answer Indicator";
                        break;
                    default:
                        break;
                }
                pollObjectModel po = new pollObjectModel();
                po.createObject(obtype, attribute, pollid);

                //return RedirectToAction("Index", new { pollid = pollid });
                return View();
            }
            catch (Exception e)
            {
                ViewData["error1"] = "!ERROR: " + e.Message;
                return View();
            }
        }