コード例 #1
0
        public IHttpActionResult PutUserAccount(int id, UserAccount userAccount)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userAccount.UserId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public dtoMailTransactionResult SendMail(dtoMailMessage eMail)
        {
            try
            {
                dtoMailTransactionResult mailResp = new dtoMailTransactionResult();
                Mail mailMessage            = new Mail();
                bool senderMailUpdateStatus = false;

                eMail = validateMailForDraft(eMail);

                var emailsToSend = eMail.ToEmail.Split(',');

                foreach (string toEmail in emailsToSend)
                {
                    mailMessage = Mapper.Map <Mail>(eMail); //mapping

                    //prepare eMail Message for Reveiver
                    PrepareReceiverMailData(mailMessage, toEmail);

                    MailStatus mailStatus = new MailStatus();
                    mailStatus.EmailId          = toEmail.Trim();
                    mailStatus.IsSentSuccessful = false;
                    using (DbContextTransaction transaction = dataContext.Database.BeginTransaction())
                    {
                        try
                        {
                            //Save reveiver Mail
                            dataContext.Mails.Add(mailMessage);
                            int resCount = dataContext.SaveChanges();

                            foreach (var dtoAttach in eMail.AttachmentsList)
                            {
                                MailAttachment mAttach = new MailAttachment();
                                mAttach.AttachmentId = 0;
                                mAttach.MailId       = mailMessage.MailId;
                                mAttach.Attachment   = dtoAttach.Attachment;

                                dataContext.MailAttachments.Add(mAttach);
                                int attRes = dataContext.SaveChanges();
                            }

                            mailStatus.MailId           = mailMessage.MailId; //
                            mailStatus.IsSentSuccessful = true;
                            mailResp.Mails.Add(mailStatus);

                            if (!senderMailUpdateStatus)
                            {
                                Mail senderMail = Mapper.Map <Mail>(eMail); //mapping
                                PrepareSenderMailData(senderMail);
                                //Update sender mail Status
                                dataContext.Entry(senderMail).State = EntityState.Modified;
                                Int32 senderReturnVal = dataContext.SaveChanges();
                                senderMailUpdateStatus = true;
                                mailResp.ResultSattus  = true;
                            }

                            transaction.Commit();

                            fileService.CopyFiles(eMail.MailId, mailMessage.MailId);
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            mailStatus.IsSentSuccessful = false;
                            mailResp.Mails.Add(mailStatus);
                        }
                    }
                }

                return(mailResp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }