Example #1
0
 public ActionResult PostLogin(User user)
 {
     if (ModelState.IsValid)
     {
         using (APIEntities api = new APIEntities())
         {
             User usr = api.Users.FirstOrDefault(u =>
                                                 u.username.Equals(user.username) &&
                                                 u.password.Equals(user.password)
                                                 );
             if (usr != null)
             {
                 string microSeconds = DateTime.Now.ToString("HH:mm:ss.ffffff");
                 string token        = Convert.ToBase64String(Encoding.UTF8.GetBytes(microSeconds));
                 usr.token = token;
                 api.SaveChanges();
                 Session.Add("user", new UserDTO {
                     UserId = usr.user_id, Username = usr.username, Token = token
                 });
                 return(Redirect("~/dashboard"));
             }
         }
     }
     return(View("Login"));
 }
Example #2
0
 public string GetTodoDelete(int id)
 {
     using (APIEntities api = new APIEntities())
     {
         var todo = api.todoes.Find(id);
         api.todoes.Remove(todo);
         api.SaveChanges();
         return("success delete ID :" + id);
     }
 }
Example #3
0
 public string GetTodoCompleted(int id)
 {
     using (APIEntities api = new APIEntities())
     {
         var todo      = api.todoes.Find(id);
         var completed = todo.completed;
         todo.completed = (completed == 1) ? 0 : 1;
         api.SaveChanges();
         return("success completed ID :" + id);
     }
 }
Example #4
0
        // POST api/<controller>
        public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
        {
            try
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                var jsonString = await request.Content.ReadAsStringAsync();
                RootObject obj = JsonConvert.DeserializeObject<RootObject>(jsonString);
                //備份進來的json string
                logger.Info((jsonString));

                using (var db = new APIEntities())
                {

                    //抓取第一層tag
                    foreach (var tag in obj.tags)
                    {
                        //抓取tag下的item list物件
                        List<Item> oItem = new List<Item>(tag.items);

                        foreach (var tItem in oItem)
                        {
                            db.ExtData.Add(new ExtData()

                            {
                                store_id = obj.store_id,
                                data_generated_dtime = obj.data_generated_dtime,
                                data_start_dtime = obj.data_start_dtime,
                                data_end_dtime = obj.data_end_dtime,
                                tag_id = tag.id,
                                tag_external_id = tag.external_id,
                                tag_setting_external_id = tag.setting_external_id,
                                tag_name = tag.name,
                                item_id = tItem.id,
                                item_external_id = tItem.external_id,
                                item_setting_external_id = tItem.setting_external_id,
                                item_name = tItem.name

                            });
                        }
                    }
                    db.SaveChanges();
                }
                return new HttpResponseMessage(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.Fatal(LogUtility.BuildExceptionMessage(ex));
                return new HttpResponseMessage(HttpStatusCode.BadRequest);
            }

        }
Example #5
0
        public ActionResult Logout()
        {
            UserDTO user = (UserDTO)Session["user"];

            using (APIEntities api = new APIEntities())
            {
                User u = api.Users.Find(user.UserId);
                u.token = null;
                api.SaveChanges();
            }
            Session["user"] = null;
            return(Redirect("~/login"));
        }
Example #6
0
 public string PostTodo(ToDoDTO todo)
 {
     using (APIEntities api = new APIEntities())
     {
         var newTodo = new todo
         {
             todo_id   = todo.ID,
             value     = todo.Value,
             completed = (todo.Completed) ? 1 : 0
         };
         api.todoes.Add(newTodo);
         api.SaveChanges();
         return("success");
     }
 }
Example #7
0
        // POST api/<controller>
        public async Task <HttpResponseMessage> Post(HttpRequestMessage request)
        {
            try
            {
                Logger logger     = LogManager.GetCurrentClassLogger();
                var    jsonString = await request.Content.ReadAsStringAsync();

                RootObject obj = JsonConvert.DeserializeObject <RootObject>(jsonString);
                //備份進來的json string
                logger.Info((jsonString));

                using (var db = new APIEntities())
                {   //直接第一層讀取
                    foreach (var item in obj.items)
                    {
                        db.RealData.Add(new RealData()
                        {
                            store_id             = obj.store_id,
                            data_generated_dtime = obj.data_generated_dtime,
                            data_start_dtime     = obj.data_start_dtime,
                            data_end_dtime       = obj.data_end_dtime,
                            item_id                  = item.id,
                            item_external_id         = item.external_id,
                            item_setting_external_id = item.setting_external_id,
                            item_name                = item.name,
                            item_category_id         = item.category_id,
                            item_category_name       = item.category_name,
                            quantity                 = Convert.ToDecimal(item.quantity)
                        });

                        db.SaveChanges();
                    }
                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.Fatal(LogUtility.BuildExceptionMessage(ex));
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }
        // GET: HotSpot
        public async Task <ActionResult> Index()
        {
            string targetURI = "http://data.ntpc.gov.tw/od/data/api/04958686-1B92-4B74-889D-9F34409B272B?$format=json";

            HttpClient client = new HttpClient();

            client.MaxResponseContentBufferSize = Int32.MaxValue;
            var response = await client.GetStringAsync(targetURI);

            var collection = JsonConvert.DeserializeObject <IEnumerable <HotSpot> >(response);

            {
                using (var db = new APIEntities())
                {
                    List <HotSpotDB> hdb = new List <HotSpotDB>();

                    foreach (var item in collection)
                    {
                        db.HotSpotDB.Add(new HotSpotDB()
                        {
                            id             = item.id,
                            spot_name      = item.spot_name,
                            type           = item.type,
                            company        = item.company,
                            district       = item.district,
                            address        = item.address,
                            apparatus_name = item.apparatus_name,
                            latitude       = item.latitude,
                            longitude      = item.longitude
                        });
                    }
                    //hdb.ToList();

                    db.SaveChanges();
                }
            }

            //ViewBag.Result = response;
            return(View());
        }