public async Task <ActionResult <IEnumerable <Message> > > GetMessagesBySeries(string series)
        {
            var selectedSeries = await _context.Series.FirstOrDefaultAsync(s => s.Name.ToLower() == series.ToLower());

            if (selectedSeries == null)
            {
                return(NotFound());
            }

            await _context.Entry(selectedSeries).Collection(s => s.Messages).LoadAsync();

            selectedSeries.Messages = selectedSeries.Messages.OrderBy(m => m.Date);
            foreach (var message in selectedSeries.Messages)
            {
                await _context.Entry(message).Reference(m => m.Video).LoadAsync();

                await _context.Entry(message).Reference(m => m.Audio).LoadAsync();

                await _context.Entry(message).Reference(m => m.Notes).LoadAsync();
            }
            var messages = selectedSeries.Messages.ToList();

            if (messages == null)
            {
                return(NotFound());
            }

            return(messages);
        }
        public async Task <IActionResult> PutConversation(string id, Conversation conversation)
        {
            if (id != conversation._id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutMessage([FromRoute] long id, [FromBody] Message message)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != message.MessageID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutMessage(int id, Message message)
        {
            if (id != message.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutMessage(UserBlocked message)
        {
            if (!message.messageType.Equals("UserBlocked"))
            {
                return(BadRequest());
            }

            var data = await _context.Messages.FindAsync(message.data.UserId);

            if (data == null)
            {
                Notifiy(message.data.UserId, "No UserId Found");
                return(NotFound());
            }
            _context.Entry(data).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessageExists(message.data.UserId))
                {
                    Notifiy(message.data.UserId, "No User Found");
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            Notifiy(message.data.UserId, "Updated");
            return(Ok());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Key)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 7
0
        public IHttpActionResult PutMessage(int id, Message message)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != message.Id)
            {
                return(BadRequest());
            }

            db.Entry(message).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 8
0
 public async Task DeleteAsync(T item)
 {
     using (MessageContext db = new MessageContext(_options))
     {
         DbSet <T> dbSet = db.Set <T>();
         db.Entry(item).State = EntityState.Deleted;
         await db.SaveChangesAsync();
     }
 }
Ejemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "Id,title,message,from,to")] Messages messages)
 {
     if (ModelState.IsValid)
     {
         db.Entry(messages).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(messages));
 }
Ejemplo n.º 10
0
 public ActionResult Edit(MessageModel messagemodel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(messagemodel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(messagemodel));
 }
Ejemplo n.º 11
0
        public ActionResult ModifyMessage()
        {
            int     id = int.Parse(Request.Form["id"]);
            Message m  = messageContext.messageLists.Find(id);

            String text = Request.Form["text"];

            text = text.Replace("#lt;", "<");
            text = text.Replace("#gt;", ">");

            m.message_reply_content = text;

            if (ModelState.IsValid)
            {
                messageContext.Entry(m).State = EntityState.Modified;
                messageContext.SaveChanges();
            }
            return(Content("修改成功"));
        }
Ejemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "Mid,Name")] Message message)
 {
     if (ModelState.IsValid)
     {
         db.Entry(message).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(message));
 }
Ejemplo n.º 13
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,MesaggeTime,MessageUser")] Message message)
        {
            if (ModelState.IsValid)
            {
                db.Entry(message).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(message));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> PutMessageBoard(long id, MessageBoard messageBoard)
        {
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            bool IsModerator = currentUser.IsInRole("Moderator");

            // var currmsg = await _context.Messages.FindAsync(id);

            if (id != messageBoard.Id)
            {
                return(BadRequest());
            }


            //  if (messageBoard.flagged != currmsg.flagged && !IsModerator)
            if (messageBoard.Flagged == true && !IsModerator)
            {
                return(StatusCode(StatusCodes.Status203NonAuthoritative, new Response {
                    Status = "Error", Message = " Flag modification not allowed(Only Moderator can update flag)"
                }));
            }

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

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

            return(Ok(new Response {
                Status = "Success", Message = "Record Updated Successfully"
            }));
        }
Ejemplo n.º 15
0
        private async Task <BaseResponse <BaseMessage> > import(BaseMessage message)
        {
            var response = BaseResponseFactory <BaseMessage> .CreateDefaultBaseResponse();

            using (var transaction = await _context.Database.BeginTransactionAsync())
            {
                if (message == null)
                {
                    _logger.LogInformation("Parameter is null");
                    response.Errors.Add(new ApiError {
                        description = "Parameter is null"
                    });
                    return(response);
                }

                if (!message.Valid)
                {
                    _logger.LogInformation("Message {Id} is not valid by provider, so we cannot process it", message.Id);
                    response.Errors.Add(new ApiError {
                        description = "Message is not valid by provider, so we cannot process it"
                    });
                    return(response);
                }

                if (message is MailgunMessage)
                {
                    var mailgunMessage = (MailgunMessage)message;

                    Mail newMail = null;

                    try
                    {
                        newMail = await _context.Mails
                                  .AsNoTracking()
                                  .FirstOrDefaultAsync(e => e.BaseMessageId == message.Id);

                        if (newMail == null)
                        {
                            newMail = new Mail(message);
                            await _context.Mails.AddAsync(newMail);

                            await _context.SaveChangesAsync();
                        }

                        if (newMail.Retries <= 0)
                        {
                            _logger.LogError("Too many reprocessed");
                            return(response);
                        }

                        bool recipientEmpty = mailgunMessage.Recipient != null?mailgunMessage.Recipient.Equals(string.Empty) : true;

                        bool toEmpty = mailgunMessage.To != null?
                                       mailgunMessage.To.Equals(string.Empty) : true;

                        if (recipientEmpty && toEmpty)
                        {
                            _logger.LogInformation("recipient and to email headers are empty");
                            response.Errors.Add(new ApiError {
                                description = "recipient and to email headers are empty"
                            });
                            return(response);
                        }

                        var toRecipient = !recipientEmpty ? new MailAddress(mailgunMessage.Recipient) : new MailAddress(mailgunMessage.To);
                        var domainFound = await _domainService.get(toRecipient.Host);

                        if (domainFound == null)
                        {
                            var errorMessage = string.Format("message id: {0} the domain {1} was not found", message.Id, toRecipient.Host);
                            await SetMailError(newMail, errorMessage);

                            _logger.LogError(errorMessage);
                            response.Errors.Add(new ApiError {
                                description = "Domain not found"
                            });
                            return(response);
                        }

                        var mailboxFound = await _mailboxService.GetMailbox(toRecipient.Address);

                        if (mailboxFound == null)
                        {
                            var newMailbox = _mailboxService.CreateDefaultMailbox(toRecipient, domainFound);
                            mailboxFound = await _mailboxService.CreateMailbox(newMailbox);
                        }

                        var mail = _mapper.Map <Mail>(mailgunMessage);

                        mail.Id            = newMail.Id;
                        mail.BaseMessageId = newMail.BaseMessageId;

                        _context.Entry(newMail).State = EntityState.Detached;

                        if (mail.Attachments.NotEmpty())
                        {
                            var jsonAttachments = mail.Attachments.Replace("\\\"", "\"");
                            var attachments     = JsonConvert.DeserializeObject <MailAttachment[]>(jsonAttachments);
                            ICollection <Task <MailAttachment> > getFiles = new List <Task <MailAttachment> >();

                            attachments.ToList().ForEach(async e =>
                            {
                                e        = await _mailgunAttachment.get(e);
                                e.MailId = mail.Id;
                                e.Id     = Guid.NewGuid();
                                await _context.AddAsync(e);
                            });

                            await _context.SaveChangesAsync();

                            mail.MailAttachmentsJobStatus = JobStats.Done;
                        }

                        mail.ErrorMessage = string.Empty;
                        mail.ErrorDate    = null;
                        mail.NextRetry    = null;

                        mail.JobStats = JobStats.Done;
                        mail.MailAttachmentsJobStatus = JobStats.Done;

                        _context.Mails.Update(mail);

                        await _context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception exception)
                    {
                        transaction.Rollback();

                        var errorMessage = string.Format("{0} - {1}", exception.Message, exception.StackTrace);
                        await SetMailError(newMail, errorMessage);

                        _logger.LogError(errorMessage);
                        response.Errors.Add(new ApiError {
                            description = errorMessage
                        });
                    }
                }
            }

            return(response);
        }
Ejemplo n.º 16
0
 public void UpdateCustomer(Customer Customer)
 {
     _context.Entry(Customer).State = EntityState.Modified;
 }