예제 #1
0
        public async Task <IActionResult> PutUserData([FromRoute] int id, [FromBody] UserData userData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userData.ID)
            {
                return(BadRequest());
            }

            _context.Entry(userData).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserDataExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task OnCommentaryActionAsync(CommentaryNotification info)
        {
            var currentDayStatistic = await _dbAccess.GetBlogDayStatisticAsync(DateTime.UtcNow.Date);

            var countDelta = info.Action switch
            {
                CommentaryAction.CREATED => 1,
                CommentaryAction.DELETED => - 1,
                _ => throw new NotSupportedException()
            };

            currentDayStatistic.CommentariesCount += countDelta;

#warning save changes should not be here
            await _db.SaveChangesAsync();
        }
예제 #3
0
        private async void backwork()
        {
            StatisticContext db2 = new StatisticContext();
            MessageQueue     InputQueue;

            if (MessageQueue.Exists(@".\private$\InputStatistic"))
            {
                InputQueue = new MessageQueue(@".\private$\InputStatistic");
            }
            else
            {
                InputQueue = MessageQueue.Create(".\\private$\\InputStatistic");
            }

            MessageQueue OutputQueue;

            if (MessageQueue.Exists(@".\private$\OutputStatistic"))
            {
                OutputQueue = new MessageQueue(@".\private$\OutputStatistic");
            }
            else
            {
                OutputQueue = MessageQueue.Create(".\\private$\\OutputStatistic");
            }

            using (InputQueue)
            {
                Statistic.Models.Statistic statistic     = new Statistic.Models.Statistic();
                InputStatisticMessage      InputMessage  = new InputStatisticMessage();
                OutputStatisticMessage     OutputMessage = new OutputStatisticMessage();
                Message msg = new Message();
                InputQueue.Formatter  = new XmlMessageFormatter(new Type[] { typeof(InputStatisticMessage) });
                OutputQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(OutputStatisticMessage) });
                while (InputQueue.CanRead)
                {
                    Message msgInput = InputQueue.Receive();

                    InputMessage = (InputStatisticMessage)msgInput.Body;

                    statistic.RequestType = InputMessage.RequestType;
                    statistic.ServerName  = InputMessage.ServerName;
                    statistic.Time        = InputMessage.Time;
                    statistic.Detail      = InputMessage.Detail;
                    statistic.State       = InputMessage.State;

                    try
                    {
                        db2.Statistics.Add(statistic);
                        await db2.SaveChangesAsync();
                    }
                    catch (DbUpdateException ex)
                    {
                        OutputStatisticMessage OutputMessageCatch = new OutputStatisticMessage();
                        OutputMessageCatch.Status  = -1;
                        OutputMessageCatch.Error   = "Error in Input Queue";
                        OutputMessageCatch.Message = InputMessage;

                        Message Msg = new Message(OutputMessageCatch);
                        switch (OutputMessageCatch.Message.ServerName)
                        {
                        case ServerName.AUTHENTICATION:
                            Msg.Label = "NON_AUTH";
                            break;

                        case ServerName.GATEWAY:
                            Msg.Label = "NON_GATEWAY";
                            break;

                        case ServerName.USERS:
                            Msg.Label = "NON_USERS";
                            break;

                        case ServerName.MACHINES:
                            Msg.Label = "NON_MACHINES";
                            break;

                        case ServerName.FINES:
                            Msg.Label = "NON_FINES";
                            break;
                        }
                        OutputQueue.Send(Msg);
                        continue;
                    }

                    OutputMessage.Status  = 0;
                    OutputMessage.Error   = "";
                    OutputMessage.Message = InputMessage;

                    msg.Body = OutputMessage;
                    switch (OutputMessage.Message.ServerName)
                    {
                    case ServerName.AUTHENTICATION:
                        msg.Label = "NON_AUTH";
                        break;

                    case ServerName.GATEWAY:
                        msg.Label = "NON_GATEWAY";
                        break;

                    case ServerName.USERS:
                        msg.Label = "NON_USERS";
                        break;

                    case ServerName.MACHINES:
                        msg.Label = "NON_MACHINES";
                        break;

                    case ServerName.FINES:
                        msg.Label = "NON_FINES";
                        break;
                    }
                    OutputQueue.Send(msg);
                }
            }
        }
예제 #4
0
 public Task Create(DailyStatistic dailyStatistic)
 {
     _context.DailyStatistics.Add(dailyStatistic);
     return(_context.SaveChangesAsync());
 }