예제 #1
0
        // GET: AcaSessions/Details/5
        public IActionResult Details(int id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(GloVar.iBaseURI);
                MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json");
                client.DefaultRequestHeaders.Accept.Add(contentType);
                HttpResponseMessage response = client.GetAsync("/api/AcaSessions/" + id).Result;
                string     stringData        = response.Content.ReadAsStringAsync().Result;
                AcaSession acaSession        = JsonConvert.DeserializeObject <AcaSession>(stringData);
                return(View(acaSession));
            }


            //var acaSession = await _context.AcaSession
            //    .SingleOrDefaultAsync(m => m.AutoId == id);
            //if (acaSession == null)
            //{
            //    return NotFound();
            //}

            //return View(acaSession);
        }
예제 #2
0
        public IActionResult Create([Bind("Ssdid,SessionName,SessionStartDate,SessionEndDate")] AcaSession acaSession)
        {
            //if (ModelState.IsValid)
            //{
            using (HttpClient client = new HttpClient())
            {
                acaSession.DBid    = mdBId;
                client.BaseAddress = new Uri(GloVar.iBaseURI);
                MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json");
                client.DefaultRequestHeaders.Accept.Add(contentType);
                string stringData            = JsonConvert.SerializeObject(acaSession);
                var    contentData           = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json");
                HttpResponseMessage response = client.PostAsync("/api/AcaSessions", contentData).Result;
                ViewBag.Message = response.Content.ReadAsStringAsync().Result;
                if (response.IsSuccessStatusCode)
                {
                    ViewBag.Remark = "Creation of Session '" + acaSession.SessionName + "' Successful";
                    return(View());
                }
                else
                {
                    ViewBag.Remark = "Creation of Session '" + acaSession.SessionName + "' Failed!. Please Try Again";
                    return(View(acaSession));
                }
            }

            //_context.Add(acaSession);
            //await _context.SaveChangesAsync();
            //return RedirectToAction("Index");
            //}
            return(View(acaSession));
        }
예제 #3
0
        public IEnumerable <AcaSession> Get(int mdBID)
        {
            List <AcaSession> acaSessList = new List <AcaSession>();
            var conn = _context.Database.GetDbConnection();

            var queryString = Request.Query;
            var skip        = Convert.ToInt32(queryString["$skip"]);
            var take        = Convert.ToInt32(queryString["$top"]);

            if (take <= 0)
            {
                take = 10;
            }
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            using (var command = conn.CreateCommand())
            {
                MySql = " SELECT SSDID, SessionName, SessionStartDate, SessionEndDate FROM AcaSession WITH (NOLOCK)";
                MySql = MySql + " WHERE  Dormant = 0";
                MySql = MySql + " AND dBID = " + mdBID;
                command.CommandType = CommandType.Text;
                command.CommandText = MySql;
                DbDataReader kMyReader = command.ExecuteReader();
                if (kMyReader.HasRows)
                {
                    while (kMyReader.Read())
                    {
                        AcaSession acaSess = new AcaSession();
                        if (!kMyReader.IsDBNull(0))
                        {
                            acaSess.Ssdid = kMyReader.GetInt32(0);
                        }
                        if (!kMyReader.IsDBNull(1))
                        {
                            acaSess.SessionName = kMyReader.GetString(1);
                        }
                        if (!kMyReader.IsDBNull(2))
                        {
                            acaSess.SessionStartDate = GenFunc.GloFunc.FromOADate(kMyReader.GetDouble(2));
                        }
                        if (!kMyReader.IsDBNull(3))
                        {
                            acaSess.SessionEndDate = GenFunc.GloFunc.FromOADate(kMyReader.GetDouble(3));
                        }
                        acaSessList.Add(acaSess);
                    }
                }
            }
            //return Json(new { result = acaSessList.Skip(skip).Take(take), count = acaSessList.Count() });
            return(acaSessList);
        }
예제 #4
0
        public async Task <IActionResult> GetAcaSession([FromRoute] int id, string dSess, int mdBId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var conn = _context.Database.GetDbConnection();

            if (conn.State == ConnectionState.Closed)
            {
                await conn.OpenAsync();
            }
            using (var command = conn.CreateCommand())
            {
                MySql = " SELECT SessionName, SessionStartDate, SessionEndDate FROM AcaSession WITH (NOLOCK)";
                MySql = MySql + " WHERE SSDID = " + id;
                MySql = MySql + " AND Dormant = 0";
                MySql = MySql + " AND dBID = " + mdBId;

                command.CommandType = CommandType.Text;
                command.CommandText = MySql;
                DbDataReader kMyReader = await command.ExecuteReaderAsync();

                if (kMyReader.HasRows)
                {
                    kMyReader.Read();
                    AcaSession acaSess = new AcaSession();
                    acaSess.Ssdid = id;
                    if (!kMyReader.IsDBNull(0))
                    {
                        acaSess.SessionName = kMyReader.GetString(0);
                    }
                    if (!kMyReader.IsDBNull(1))
                    {
                        acaSess.SessionStartDate = GenFunc.GloFunc.FromOADate(kMyReader.GetDouble(1));
                    }
                    if (!kMyReader.IsDBNull(2))
                    {
                        acaSess.SessionEndDate = (GenFunc.GloFunc.FromOADate(kMyReader.GetDouble(2)));
                    }
                    return(Ok(acaSess));
                }
                else
                {
                    return(NotFound());
                }
            }
        }
예제 #5
0
        public async Task <IActionResult> PutAcaSession([FromBody] AcaSession acaSession)
        {
            var ssid = acaSession.Ssdid;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var conn = _context.Database.GetDbConnection();
                if (conn.State == ConnectionState.Closed)
                {
                    await conn.OpenAsync();
                }
                using (var command = conn.CreateCommand())
                {
                    MySql = " UPDATE AcaSession SET ";
                    MySql = MySql + " SessionName = '" + acaSession.SessionName;
                    MySql = MySql + "', SessionStartDate = " + GenFunc.GloFunc.ToOADate(acaSession.SessionStartDate);
                    MySql = MySql + ", SessionEndDate = " + GenFunc.GloFunc.ToOADate(acaSession.SessionEndDate);
                    MySql = MySql + " WHERE SSDID = " + acaSession.Ssdid;
                    MySql = MySql + " AND Dormant = 0";
                    MySql = MySql + " AND dBID = " + acaSession.DBid;

                    command.CommandType = CommandType.Text;
                    command.CommandText = MySql;
                    command.ExecuteNonQuery();
                }
                //UpdateAcaSession(acaSession);
                //    await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AcaSessionExists(ssid))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #6
0
        public async Task <IActionResult> Edit([Bind("AutoId,Ssdid,SessionName,SessionStartDate,SessionEndDate,Dormant,LoginName,ModTime,CTerminal,DBid")] AcaSession acaSession)
        {
            //if (id != acaSession.AutoId)
            //{
            //    return NotFound();
            //}

            if (ModelState.IsValid)
            {
                try
                {
                    using (HttpClient client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(GloVar.iBaseURI);
                        MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json");
                        client.DefaultRequestHeaders.Accept.Add(contentType);
                        string stringData            = JsonConvert.SerializeObject(acaSession);
                        var    contentData           = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json");
                        HttpResponseMessage response = client.PutAsync("/api/AcaSessions/" + acaSession.AutoId, contentData).Result;
                        ViewBag.Message = response.Content.ReadAsStringAsync().Result;
                        //return View(acaSession);
                    }

                    //_context.Update(acaSession);
                    //await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AcaSessionExists(acaSession.AutoId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(acaSession));
        }
예제 #7
0
        public async Task <IActionResult> PostAcaSession([FromBody] AcaSession acaSession)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var conn = _context.Database.GetDbConnection();
                if (conn.State == ConnectionState.Closed)
                {
                    await conn.OpenAsync();
                }
                using (var command = conn.CreateCommand())
                {
                    MySql = " INSERT INTO AcaSession (ssdid, SessionName, SessionStartDate, SessionEndDate, ";
                    MySql = MySql + " Dormant, LoginName, ModTime, cTerminal, dBID) Values (0, '";
                    MySql = MySql + acaSession.SessionName + "'," + GenFunc.GloFunc.ToOADate(acaSession.SessionStartDate) + ",";
                    MySql = MySql + GenFunc.GloFunc.ToOADate(acaSession.SessionEndDate) + ", 0,'" + strLoginName + "'," + GenFunc.GloFunc.ToOADate(DateTime.Now);
                    MySql = MySql + ",'" + Terminal + "'," + acaSession.DBid + ")";

                    command.CommandType = CommandType.Text;
                    command.CommandText = MySql;
                    command.ExecuteNonQuery();
                }
                //UpdateAcaSession(acaSession);
                //    await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            //_context.AcaSession.Add(acaSession);
            //await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAcaSession", new { id = acaSession.AutoId }, acaSession));
        }
예제 #8
0
 public static Boolean UpdateAcaSession(AcaSession acaSession)
 {
     return(true);
 }