예제 #1
0
        public MainWindow()
        {
            InitializeComponent();
            logService = new LogService();
            logService.Add("\n\nProgram started\n");

            /*try
             * {
             *  logService.Add("Getting credentials...");
             *
             *  CredentialService credentialService = new CredentialService();
             *  config = credentialService.GetCredentials();
             *
             *  logService.Add("Success");
             * }
             * catch (Exception e)
             * {
             *  logService.Add("Failed");
             *  logService.Add("Creating credentials file");
             *
             *  CredentialWindow credentialWindow = new CredentialWindow();
             *  credentialWindow.ShowDialog();
             * }*/

            try
            {
                LoadSchedule();
            }
            catch
            {
                logService.Add("Schedule loading failed");
            }
        }
예제 #2
0
        public ActionResult Login(string userName, string passWord, string ip, string city)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(passWord) || string.IsNullOrEmpty(ip))
            {
                return(Json(new AjaxResult {
                    Status = "Error", ErrorMsg = "Username or password can't be empty!"
                }));
            }
            var user = UserService.GetUserByUserName(userName);

            if (user != null)
            {
                if (UserService.CheckLogin(userName, passWord))
                {
                    SessionHelper.Add("userId", user.Id.ToString(), 60);
                    SessionHelper.Add("userName", user.UserName, 60);
                    SessionHelper.Add("profilePic", user.ProfilePic, 60);
                    SessionHelper.Add("IP", ip, 60);
                    SessionHelper.Add("CityName", city, 60);
                    LogService.Add(user.Id, 0, string.Format("在{0}登陆成功", city), ip);//日志记录用户登录
                    return(Json(new AjaxResult {
                        Status = "OK", Data = user.Id
                    }));
                }
            }
            return(Json(new AjaxResult {
                Status = "Error", ErrorMsg = "wrong user name or password"
            }));
        }
예제 #3
0
        public async Task <ResponceModel> Get(int id)
        {
            try
            {
                var result = new { breadcrumb = _categoryService.GetParent(id), category = (await _categoryService.Get(id).FirstOrDefaultAsync()).Adapt <CategoryDTO>(), subcategories = (_categoryService.GetByUpper(id)) };
                return(new ResponceModel(200, "OK", result, null));
            }
            catch (Exception ex)
            {
                await _logService.Add(new SystemLog()
                {
                    Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = _categoryService.GetType().Name
                });

                return(new ResponceModel(500, "ERROR", null, new string[] { "Bir sorun oluştu." }));
            }
        }
예제 #4
0
        public async Task <ResponceModel> GetAll([FromRoute] int postId)
        {
            try
            {
                var postComments = await _postCommentService.GetAll(postId);

                return(new ResponceModel(200, "OK", postComments, null));
            }
            catch (Exception ex)
            {
                await _logService.Add(new SystemLog()
                {
                    Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = _postCommentService.GetType().Name
                });

                return(new ResponceModel(500, "ERROR", null, new string[] { "Veriler getirilirken bir sorun oluştu." }));
            }
        }
예제 #5
0
        public async Task <ResponceModel> GetAll([FromQuery(Name = "text")] string text, [FromQuery(Name = "page")] int page = 1, [FromQuery(Name = "offset")] int offset = 20)
        {
            try
            {
                var companyTypes = await companyTypeService.GetAll(text, page, offset);

                return(new ResponceModel(200, "OK", companyTypes, null));
            }
            catch (Exception ex)
            {
                await _logService.Add(new SystemLog()
                {
                    Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = companyTypeService.GetType().Name
                });

                return(new ResponceModel(500, "ERROR", null, new string[] { "Şirketler getirilirken bir hata oluştu." }));
            }
        }
예제 #6
0
        public ActionResult DataGridAction()
        {
            var data = _accountingService.Lookup().ToList();

            data = data.OrderByDescending(x => x.Date).ToList();
            _logService.Add(DateTime.Now, "取得內容");
            _unitOfWork.Commit();
            return(View(data));
        }
예제 #7
0
 public ActionResult Logout()
 {
     if (!string.IsNullOrEmpty(SessionHelper.Get("userId")))
     {
         LogService.Add(Convert.ToInt64(SessionHelper.Get("userId")), 1, string.Format("在{0}退出登录", SessionHelper.Get("CityName")), SessionHelper.Get("IP"));
     }
     Session.Clear();
     return(Redirect("/User/Login"));
 }
예제 #8
0
        public async Task <ResponceModel> GetAll([FromQuery(Name = "text")] string text, [FromQuery(Name = "category")] int category, [FromQuery(Name = "page")] int page = 1, [FromQuery(Name = "offset")] int offset = 20)
        {
            try
            {
                var posts = await postService.GetAll(text, category, page, offset);

                return(new ResponceModel(200, "OK", posts, null));
            }
            catch (Exception ex)
            {
                await _logService.Add(new SystemLog()
                {
                    Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = postService.GetType().Name
                });

                return(new ResponceModel(500, "ERROR", null, new string[] { "Gönderililer getirilirken bir sorun oluştu." }));
            }
        }
예제 #9
0
        public ActionResult Delete(Guid?Id)
        {
            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AccountBook data = _MoneyService.GetSingle(Id.Value);

            if (data == null)
            {
                return(HttpNotFound());
            }

            _MoneyService.Delete(data);
            _LogService.Add(data.Categoryyy, data.Amounttt, "Delete");
            _MoneyService.Save();

            return(RedirectToAction("List"));
        }
예제 #10
0
        public IHttpActionResult PostLog(Log log)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _logService.Add(log);

            return(CreatedAtRoute("DefaultApi", new { id = log.LogId }, log));
        }
예제 #11
0
        public async Task <ResponceModel> Get()
        {
            var identifier = User.Claims.FirstOrDefault(p => p.Type == "id");

            if (identifier == null)
            {
                return(new ResponceModel(401, "Unauthorized", null, new string[] { "Yetkilendirme Hatası." }));
            }
            try
            {
                var user = (await _userService.GetById(int.Parse(identifier.Value))).Adapt <UserDTO>();
                return(new ResponceModel(200, "OK", user, null));
            }
            catch (Exception ex)
            {
                await _logService.Add(new SystemLog { Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = _userService.GetType().Name });

                return(new ResponceModel(500, "ERROR", null, new string[] { "Bir sorun oluştu." }));
            }
        }
        public void Log_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    LogService logService = new LogService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);

                    int count = 0;
                    if (count == 1)
                    {
                        // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used]
                    }

                    Log log = GetFilledRandomLog("");

                    // -------------------------------
                    // -------------------------------
                    // CRUD testing
                    // -------------------------------
                    // -------------------------------

                    count = logService.GetLogList().Count();

                    Assert.AreEqual(count, (from c in dbTestDB.Logs select c).Count());

                    logService.Add(log);
                    if (log.HasErrors)
                    {
                        Assert.AreEqual("", log.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, logService.GetLogList().Where(c => c == log).Any());
                    logService.Update(log);
                    if (log.HasErrors)
                    {
                        Assert.AreEqual("", log.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, logService.GetLogList().Count());
                    logService.Delete(log);
                    if (log.HasErrors)
                    {
                        Assert.AreEqual("", log.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, logService.GetLogList().Count());
                }
            }
        }
예제 #13
0
        public CredentialWindow()
        {
            InitializeComponent();

            logService = new LogService();
            try
            {
                logService.Add("Getting credentials...");

                ConfigService credentialService = new ConfigService();
                credentialService.GetCredentials();

                logService.Add("Success");

                OpenMainWindow();
            }
            catch
            {
                logService.Add("Failed");
                logService.Add("Creating credentials file");
            }
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,Date,Title,Note,FurtherNote,Category")] LogModel log)
        {
            log.Date = DateTime.Now;

            if (ModelState.IsValid)
            {
                await _logService.Add(log);

                return(RedirectToAction("Index"));
            }

            return(View(log));
        }
예제 #15
0
        public void AddTest()
        {
            //arrange
            var applicationContext = SetUpApplicationContext();
            var logService         = new LogService(applicationContext);
            var log = new Log()
            {
                CreatedAt = DateTime.Now, Data = "test", Endpoint = "/"
            };

            //act
            logService.Add(log);
            //assert
            Assert.Equal(4, applicationContext.Logs.Count());
        }
예제 #16
0
        /// <summary>
        /// Update and apply app's configuration
        /// </summary>
        public override void AssignIngameConfiguration( )
        {
            GraphicsDeviceMNG.IsFullScreen              = WindowFullscreen;
            GraphicsDeviceMNG.PreferredBackBufferWidth  = WindowWidth;
            GraphicsDeviceMNG.PreferredBackBufferHeight = WindowHeight;
            GraphicsDeviceMNG.ApplyChanges( );

            AudioHelper.SoundVolume  = SoundVolume;
            AudioHelper.MusicVolume  = MusicVolume;
            AudioHelper.MasterVolume = MasterVolume;
            AudioHelper.Update( );

            LogService.Add($"Saving configuration");

            CreateOrSaveConfiguration( );
        }
예제 #17
0
        public ActionResult Add([Bind(Include = "Category,Amount,BillingDate,Memo")] MoneyAddViewModels MoneyAdd)
        {
            ViewData["CategoryList"] = new SelectList(DataDict.Category, "key", "value");

            if (ModelState.IsValid)
            {
                _MoneyService.Add(MoneyAdd);
                _LogService.Add(MoneyAdd.Category, MoneyAdd.Amount, "Add");
                _MoneyService.Save();

                //System.Threading.Thread.Sleep(3000);    //測試ajax
                //return View();
                return(PartialView("List", _MoneyService.GetDataEF())); //加入ajax
            }

            return(View());
        }
        /// <summary>
        /// Creates a new game
        /// </summary>
        /// <param name="playerName">Player's name</param>
        public void NewGame(string playerName = null)
        {
            _camera = new CameraService(0.25f, new Vector2(_config.WindowWidth / 2, _config.WindowHeight / 2))
            {
                MinScale    = 0.20f,
                MaxScale    = 0.75f,
                ScaleFactor = 0.05f
            };
            _level = new Level( );
            _level.GenerateMap(20, 20);
            List <WorldTile> tiles = _level.Map.Where(tile => !tile.IsWall).ToList( );
            WorldTile        tile  = tiles.ElementAt(RandomService.GetRandomInt(tiles.Count));

            _player = new Player(_content, _config, playerName ?? "Unknown", tile.DisplayX, tile.DisplayY);

            LogService.Add($"Player spawned at [{tile.X}, {tile.Y}] ({_player.X:0}, {_player.Y:0})");
        }
예제 #19
0
        public ActionResult Create([Bind(Exclude = "Id")] AccountBook accountBook)
        {
            if (ModelState.IsValid)
            {
                accountBook.Id = Guid.NewGuid();
                _AccountBookService.Add(accountBook);
                _LogService.Add(ControllerContext.RouteData.Values["action"].ToString(), "Id=" + accountBook.Id.ToString());

                //_AccountBookService.Save();
                //_LogService.Save();
                _unitOfWork.Commit();
                return(RedirectToAction("Index"));
            }

            IList <SelectListItem> list = this.GetCategoryList();

            ViewData["categoryList"] = list;
            return(View(accountBook));
        }
예제 #20
0
        private void LoadSchedule()
        {
            logService.Add("Reading credentials file...");

            // Login user and set cookies
            ConfigService credentialService = new ConfigService();

            config = credentialService.GetCredentials();

            logService.Add("Success");
            logService.Add("Logging in user...");

            LoginService loginService = new LoginService(config.LoginUrl);

            cookieContainer = loginService.Authorize(config.Credential);

            logService.Add("Success");
            logService.Add("Parsing schedule...");

            // Get Schedule (rozvrh)
            string url = config.ScheduleUrl;

            if ((DateTime.Today.DayOfWeek.ToString() == "Saturday" || DateTime.Today.DayOfWeek.ToString() == "Sunday") && config.DisplayNextWeekFromSaturday == true)
            {
                url += "?s=next";
            }
            ScheduleService scheduleService = new ScheduleService(cookieContainer, url);;

            scheduleService.GetHtmlPage();
            Schedule schedule = scheduleService.GetSchedule();

            logService.Add("Success");
            logService.Add("Generating schedule...");

            ScheduleGeneratorService scheduleGenerator = new ScheduleGeneratorService(schedule, ScheduleContentGrid);

            scheduleGenerator.GenerateSchedule();

            logService.Add("Success");
        }
예제 #21
0
        private void loadsession(Members_Members info)
        {
            AccountServices service = new AccountServices();
            LogAccountLogin infolog = new LogAccountLogin();

            infolog.LoginIP   = System.Web.HttpContext.Current.Request.UserHostAddress;
            infolog.LoginName = info.UserName;
            infolog.Mid       = info.Id;
            LogService logservice = new LogService();

            logservice.Add(infolog);

            SessionHelper.userid     = info.Id.ToString();
            SessionHelper.username   = info.UserName;
            SessionHelper.usertype   = info.UserType.ToString();
            SessionHelper.name       = info.UserRealName;
            SessionHelper.usermobile = info.Tel;
            SessionHelper.userface   = info.ImageUrl;
            //SessionHelper.islogin==true;
        }
예제 #22
0
        private void UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            Config config = new Config()
            {
                Domain     = UrlTextBox.Text,
                Credential = new Credential()
                {
                    Username = UsernameTextBox.Text,
                    Password = PasswordTextBox.Password,
                },
            };

            ConfigService credentialService = new ConfigService();

            credentialService.SetCredentials(config);

            logService.Add("Credentials file created");

            OpenMainWindow();
        }
예제 #23
0
        public IHttpActionResult Post([FromBody] Log log, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                LogService logService = new LogService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!logService.Add(log))
                {
                    return(BadRequest(String.Join("|||", log.ValidationResults)));
                }
                else
                {
                    log.ValidationResults = null;
                    return(Created <Log>(new Uri(Request.RequestUri, log.LogID.ToString()), log));
                }
            }
        }
예제 #24
0
        public ActionResult ResetPassword(long userId, string verifyCode, string userName, string pwd)
        {
            if (userId == 0 || string.IsNullOrEmpty(verifyCode) || string.IsNullOrEmpty(pwd))
            {
                return(Json(new AjaxResult {
                    Status = "Error", ErrorMsg = "信息不完整"
                }));
            }
            //查询验证码是否有效
            var verify = VerifyService.GetVerify(userId);

            if (verify == null)
            {
                return(Json(new AjaxResult {
                    Status = "Error", ErrorMsg = "验证码无效"
                }));
            }
            //判断用户名是否输入正确
            var user = UserService.GetUserById(userId);

            if (user.UserName != userName)
            {
                return(Json(new AjaxResult {
                    Status = "Error", ErrorMsg = "用户名错误"
                }));
            }
            //重置密码
            if (UserService.ResetPassword(userId, pwd))
            {
                //修改验证码状态
                VerifyService.UpdateValid(userId);
                LogService.Add(userId, 7, "重置密码成功");
                return(Json(new AjaxResult {
                    Status = "OK"
                }));
            }
            return(Json(new AjaxResult {
                Status = "Error", ErrorMsg = "修改密码失败,请稍后重试"
            }));
        }
예제 #25
0
        public ActionResult RePost(long rePostId, string content, string ip, string city)
        {
            if (Session["userId"] == null)
            {
                return(Json(new AjaxResult {
                    Status = "NoLogin", ErrorMsg = "Not logged in user"
                }));
            }
            var post = PostService.GetPostInfo(rePostId);

            if (post == null)
            {
                return(Json(new AjaxResult {
                    Status = "Failed", ErrorMsg = "Please refresh and try again"
                }));
            }
            PostService.Add(Convert.ToInt64(Session["userId"]), content, post.DisplayUrl, city);
            LogService.Add(Convert.ToInt64(Session["userId"]), 2, string.Format("{0}在{1}转发帖子成功", Session["userName"], city), ip);
            return(Json(new AjaxResult {
                Status = "OK"
            }));
        }
예제 #26
0
        public ActionResult Posting(string content, string base64Data, string ip, string city)
        {
            if (Session["userId"] == null)
            {
                Session.Clear();
                //return Json(new AjaxResult { Status = "Error", ErrorMsg = "未登录用户" });
                return(Redirect("/User/Login"));
            }
            //上传到文件服务器(七牛云)
            string url = Common.ImageHelper.UploadStream(Common.ImageHelper.ImgBase64ToStream(base64Data));

            if (string.IsNullOrEmpty(url))
            {
                return(Json(new AjaxResult {
                    Status = "Failed", ErrorMsg = "Failed to upload picture"
                }));
            }
            PostService.Add(Convert.ToInt64(Session["userId"]), content, url, city);
            LogService.Add(Convert.ToInt64(Session["userId"]), 2, string.Format("{0}在{1}发帖成功", Session["userName"], city), ip);
            return(Json(new AjaxResult {
                Status = "OK"
            }));
        }
예제 #27
0
        public ActionResult Unfollow(long userId)
        {
            long accountId = 0;

            if (Session["userId"] == null || !long.TryParse(Session["userId"].ToString(), out accountId))
            {
                Session.Clear();
                return(Redirect("/User/Login"));
            }
            if (userId != accountId || userId == 0)
            {
                if (FollowService.Unfollow(accountId, userId))
                {
                    LogService.Add(accountId, 4, string.Format("{0}成功取消关注{1}", accountId, userId));
                    return(Json(new AjaxResult {
                        Status = "OK"
                    }));
                }
            }
            return(Json(new AjaxResult {
                Status = "Error", ErrorMsg = "Unfollow 失败"
            }));
        }
예제 #28
0
        public ActionResult Register(string userName, string fullName, string passWord, string verifyCode, string ip, string city)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(fullName) || string.IsNullOrEmpty(passWord) || string.IsNullOrEmpty(verifyCode) || string.IsNullOrEmpty(ip))
            {
                return(Json(new AjaxResult {
                    Status = "Error", ErrorMsg = "The user info cannot be empty"
                }));
            }
            string cacheVerifyCode = TempData["verifyCode"].ToString();

            if (string.IsNullOrEmpty(verifyCode) || verifyCode != cacheVerifyCode)
            {
                return(Json(new AjaxResult {
                    Status = "Error", ErrorMsg = "Verification code error, please re-enter"
                }));
            }
            long userId = UserService.Add(userName, fullName, passWord);

            LogService.Add(userId, 1, string.Format("在{0}注册账号成功", city), ip);
            return(Json(new AjaxResult {
                Status = "OK"
            }));
        }
예제 #29
0
        public async Task RefreshToken()
        {
            string link = $"https://twitchtokengenerator.com/api/refresh/{refreshtoken}";
            string responsestring;
            HttpResponseMessage response = await clienthttp.GetAsync(link);

            if (response.IsSuccessStatusCode)
            {
                responsestring = await response.Content.ReadAsStringAsync();
            }
            else
            {
                responsestring = "";
            }

            var o = JObject.Parse(responsestring);

            accesstoken = (string)o["token"];

            logService.Add($"Token has been resreshed", MessageType.Type.EVENT,
                           MethodBase.GetCurrentMethod().DeclaringType);
        }
예제 #30
0
 public JsonResult Add(Logs model)
 {
     return(Json(LogService.Add(model)));
 }