Ejemplo n.º 1
0
        public bool AddAction(AddActionDTO addActionDTO)
        {
            try
            {
                Models.Action lastAction = GetLastAction(addActionDTO);

                if (lastAction != null && CompareDates(DateTime.Now, lastAction.Date, 900))
                {
                    return(true);
                }

                Models.Action action = new Models.Action()
                {
                    ActionTypeId = addActionDTO.ActionTypeId,
                    Ip           = addActionDTO.Ip,
                    Date         = DateTime.Now,
                    DeviceTypeId = addActionDTO.DeviceTypeId
                };

                dbContext.Actions.Add(action);
                dbContext.SaveChanges();

                if (dbContext.IpLocations.FirstOrDefault(x => x.Ip == addActionDTO.Ip) == null)
                {
                    AddIpLocation(addActionDTO.Ip);
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
 public IActionResult AddAction([FromBody] AddActionDTO addActionDTO)
 {
     if (actionManager.AddAction(addActionDTO))
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 3
0
        public bool AddMessage(AddMessageDTO addMessageDTO)
        {
            try
            {
                Message message = new Message()
                {
                    Email = addMessageDTO.Email,
                    Name  = addMessageDTO.Name,
                    Text  = addMessageDTO.Text,
                    Date  = DateTime.Now
                };

                dbContext.Messages.Add(message);
                dbContext.SaveChanges();

                AddActionDTO action = new AddActionDTO()
                {
                    Ip           = addMessageDTO.Ip,
                    ActionTypeId = 2,
                    DeviceTypeId = addMessageDTO.DeviceTypeId
                };

                actionManager.AddAction(action);

                emailSender.SendEmail(new List <string>()
                {
                    "*****@*****.**", "*****@*****.**"
                },
                                      $"Новое сообщение от {addMessageDTO.Name}", FormMessageText(addMessageDTO));

                SendFeedback(addMessageDTO);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
 private Models.Action GetLastAction(AddActionDTO addActionDTO)
 {
     return(dbContext.Actions.Where(a => a.Ip == addActionDTO.Ip && a.Date == dbContext.Actions.Max(d => d.Date) &&
                                    a.ActionTypeId == addActionDTO.ActionTypeId).FirstOrDefault());
 }