コード例 #1
0
ファイル: MsSqlLogService.cs プロジェクト: rbashir/Crypztone
        public bool Update(LogTO log)
        {
            if (log.LogId < 1) return false;

            db.Entry(log).State = System.Data.EntityState.Modified;
            db.SaveChanges();
            return true;
        }
コード例 #2
0
        public ActionResult Create(LogTO logto)
        {
            if (ModelState.IsValid)
            {
                db.Insert(logto);
                return RedirectToAction("Index");
            }

            return View(logto);
        }
コード例 #3
0
ファイル: LogController.cs プロジェクト: rbashir/Crypztone
        public HttpResponseMessage PostLog(LogTO item)
        {
            if (!ModelState.IsValid)
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);

            item = sqlService.Insert(item);
            var response = Request.CreateResponse<LogTO>(HttpStatusCode.Created, item);

            string uri = Url.Link("DefaultApi", new { id = item.LogId });
            response.Headers.Location = new Uri(uri);
            return response;
        }
コード例 #4
0
ファイル: LogAPITest.cs プロジェクト: rbashir/Crypztone
        private LogTO InsertLog(string message, string source, LogTO.LogType type)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(URL);

            // Add an Accept header for JSON format.
            client.DefaultRequestHeaders.Accept.Add(new  MediaTypeWithQualityHeaderValue("application/json"));

            // Create a new product
            var log = new LogTO() { Message = message, Source = source, Type = type.ToString() };
            Uri logUri = null;
            HttpResponseMessage response = client.PostAsJsonAsync(API, log).Result;

            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.AreEqual((int)response.StatusCode, 201, "Failed to create");

            logUri = response.Headers.Location;

            int id;
            if (!int.TryParse(logUri.Segments.GetValue(logUri.Segments.Length - 1).ToString(), out id))
            {
                Assert.Fail("Failed to find log id");
            }

            log.LogId = id;
            response = client.GetAsync( API + "/" + id.ToString()).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);

            var insertedLog = response.Content.ReadAsAsync<LogTO>().Result;

            Assert.AreEqual(log.LogId, insertedLog.LogId, "Failed to insert");

            Assert.AreEqual(message, insertedLog.Message,"Message are not equal");
            Assert.AreEqual(source, insertedLog.Source,"Source is not equal");
            Assert.AreEqual(type.ToString(), insertedLog.Type,"type is not same");

            return insertedLog;
        }
コード例 #5
0
        public ActionResult Edit(LogTO logto)
        {
            if (ModelState.IsValid)
            {

                db.Update(logto);
                return RedirectToAction("Index");
            }
            return View(logto);
        }
コード例 #6
0
ファイル: LogMsSQLTest.cs プロジェクト: rbashir/Crypztone
        private LogTO InsertLog(string message, string source, LogTO.LogType type)
        {
            IMsSqlLogService repository = new MsSqlLogService();
            LogController controller = new LogController(repository);
            LogTO log = new LogTO();
            log.Message = message;
            log.Source = source;
            log.Type = type.ToString();
            LogTO insertedLog =  repository.Insert(log);

            Assert.AreNotEqual(0, insertedLog.LogId, "Failed to insert");

            Assert.AreEqual(message, insertedLog.Message,"Message are not equal");
            Assert.AreEqual(source, insertedLog.Source,"Source is not equal");
            Assert.AreEqual(type.ToString(), insertedLog.Type,"type is not same");

            return insertedLog;
        }
コード例 #7
0
ファイル: MsSqlLogService.cs プロジェクト: rbashir/Crypztone
 /// <summary>
 ///  pass log object and get the object back with new id
 /// </summary>
 /// <param name="log"></param>
 /// <returns></returns>
 public LogTO Insert(LogTO log)
 {
     db.DB_Log.Add(log);
     db.SaveChanges();
     return log;
 }