Ejemplo n.º 1
0
        private async Task SendMessage()
        {
            IsBusy = true;

            Message message = new Message()
            {
                Body        = MessageBody,
                From        = UserName,
                RecipientId = ApplicationCache.SelectedFriend.Id
            };

            var serialized = JsonConvert.SerializeObject(message);
            var jtoken     = JToken.Parse(serialized);

            try
            {
                var result = await MobileServiceClientWrapper.Instance.Client.InvokeApiAsync("notifications/send", jtoken, HttpMethod.Post, null);
            }
            catch (Exception ex)
            {
                MessageRecipient = "Not found";
                await Task.Delay(1000);
            }

            DatabaseService.Add <SentMessage>(new SentMessage(ApplicationCache.SelectedFriend.Name, MessageBody, DateTime.Now.ToString()));
            Messenger.Default.Send <RefreshHistoryMessage>(new RefreshHistoryMessage());
            Logger.TrackEvent(UserName, EventType.MessageSent);

            IsBusy      = false;
            MessageSent = true;
        }
        public JsonResult AddSchedule([FromBody] ScheduleItem scheduleItem)
        {
            if (scheduleItem != null)
            {
                try
                {
                    _databaseService.Add("Schedule", scheduleItem);
                }
                catch (Exception e)
                {
                    return(new JsonResult(new
                    {
                        message = "Ошибка при добавлении расписания!" +
                                  " Попробуйте позже",
                        status = 502
                    }));
                }

                return(new JsonResult(new
                {
                    message = "Расписание успешно добавлено",
                    status = 200
                }));
            }

            return(new JsonResult(new
            {
                status = 404
            }));
        }
Ejemplo n.º 3
0
        public JsonResult ChangeTeachers([FromBody] TeachersItem teachersItem)
        {
            if (teachersItem != null)
            {
                var filter = Builders <TeachersItem> .Filter.Eq("userId", teachersItem.UserId);

                var teachers = _databaseService.GetItemsByFilter("Teachers", filter);
                if (teachers == null)
                {
                    try
                    {
                        _databaseService.Add("Teachers", teachersItem);
                    }
                    catch (Exception e)
                    {
                        return(new JsonResult(new
                        {
                            message = "Ошибка при добавлении информации о преподавателях!" +
                                      " Попробуйте позже",
                            status = 502
                        }));
                    }

                    return(new JsonResult(new
                    {
                        message = "Информация успешно добавлена",
                        status = 200
                    }));
                }
                else
                {
                    try
                    {
                        _databaseService.ChangeTeachers(teachersItem);
                    }
                    catch (Exception e)
                    {
                        return(new JsonResult(new
                        {
                            message = "Ошибка при изменении информации о пользователе! " +
                                      "Попробуйте позже",
                            status = 502
                        }));
                    }

                    return(new JsonResult(new
                    {
                        message = "Информация успешно изменена",
                        status = 200
                    }));
                }
            }

            return(new JsonResult(new
            {
                status = 404
            }));
        }
Ejemplo n.º 4
0
        public async Task <Post> InsertPostAsync(Post post)
        {
            _context.Add(post);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception exp)
            {
                _logger.LogError($"Error in {nameof(InsertPostAsync)}: " + exp.Message);
                return(null);
            }

            return(post);
        }
Ejemplo n.º 5
0
        public async Task <User> InsertUserAsync(User user)
        {
            _context.Add(user);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception exp)
            {
                _logger.LogError($"Error in {nameof(InsertUserAsync)}: " + exp.Message);
                return(null);
            }

            return(user);
        }
Ejemplo n.º 6
0
        public override void Play(int row, int column, FieldAction action)
        {
            var state = GameState;

            base.Play(row, column, action);

            if (state != GameState.Won && GameState == GameState.Won)
            {
                var official = _officialGamemodes.FirstOrDefault(g => g.Bombs == Gamemode.Bombs &&
                                                                 g.Width == Gamemode.Width &&
                                                                 g.Height == Gamemode.Height &&
                                                                 g.Name == Gamemode.Name);

                if (official != null)
                {
                    _database.Add(Gamemode, _nickname, RoundTime, StopTime);
                }
            }
        }
        public JsonResult Register([FromBody] UserItem userItem)
        {
            if (userItem != null)
            {
                var filter = Builders <UserItem> .Filter.Eq("email", userItem.Email);

                if (_databaseService.GetItemsByFilter("Users", filter) != null)
                {
                    return(new JsonResult(new
                    {
                        message = "Пользователь с данным email уже существует",
                        status = 417
                    }));
                }

                try
                {
                    _databaseService.Add("Users", userItem);
                }
                catch (Exception e)
                {
                    return(new JsonResult(new
                    {
                        message = "Ошибка регистрации! Попробуйте позже",
                        status = 502
                    }));
                }

                return(new JsonResult(new
                {
                    message = "Регистрация прошла успешно",
                    status = 200
                }));
            }

            return(new JsonResult(new
            {
                status = 404
            }));
        }
        public JsonResult AddHomework([FromBody] HomeworkItem homeworkItem)
        {
            if (homeworkItem != null)
            {
                var scheduleFilter = Builders <ScheduleItem> .Filter.Eq("userId", homeworkItem.UserId);

                var userFilter = Builders <UserInfoItem> .Filter.Eq("userId", homeworkItem.UserId);

                var userResult     = _databaseService.GetItemsByFilter("UsersInfo", userFilter);
                var scheduleResult = _databaseService.GetItemsByFilter("Schedule", scheduleFilter);


                if (userResult == null)
                {
                    return(new JsonResult(new
                    {
                        message = "Заполните информацию о пользователе",
                        status = 404
                    }));
                }

                try
                {
                    if (scheduleResult != null)
                    {
                        if (Utils.IsSubjectExistInWeek(homeworkItem, scheduleResult[0]))
                        {
                            _databaseService.Add("Homework", homeworkItem);
                        }
                        else
                        {
                            return(new JsonResult(new
                            {
                                message = "На выбранной неделе нет выбранного предмета!",
                                status = 404
                            }));
                        }
                    }
                }
                catch (Exception e)
                {
                    return(new JsonResult(new
                    {
                        message = "Ошибка при добавлении домашнего задания!" +
                                  " Попробуйте позже",
                        status = 502
                    }));
                }

                return(new JsonResult(new
                {
                    message = "Домашнее задание успешно добавлено",
                    status = 200
                }));
            }

            return(new JsonResult(new
            {
                status = 404
            }));
        }