public void CreateNewMessageSync(CorrespondenceNoteBindingModel message, int senderRole)
        {
            var resource = db.ResourcesReferences.SingleOrDefault(r => r.TokenValue == message.resourceToken);
            EDISAngular.Infrastructure.DbFirst.Note note = new EDISAngular.Infrastructure.DbFirst.Note()
            {
                AccountId = "",
                AdviserId = message.adviserNumber,
                AssetTypeId = message.assetTypeId,
                Body = message.body,
                ClientId = message.clientId,
                DateCompleted = message.dateCompleted,
                DateCreated = DateTime.Now,
                DateDue = message.dateDue,
                DateModified = DateTime.Now,
                FollowupActions = message.followupActions,
                FollowupDate = message.followupDate,
                IsAccepted = message.isAccepted,
                IsDeclined = message.isDeclined,
                NoteType = message.noteTypeId,
                NoteId = Guid.NewGuid().ToString(),
                Subject = message.subject,
                SenderRole = senderRole
            };
            db.Notes.Add(note);
            if (!string.IsNullOrEmpty(resource.ResourceUrl))
            {
                EDISAngular.Infrastructure.DbFirst.Attachment attachment = new EDISAngular.Infrastructure.DbFirst.Attachment()
                {
                    AttachmentId = Guid.NewGuid().ToString(),
                    DateCreated = DateTime.Now,
                    DateModified = DateTime.Now,
                    NoteId = note.NoteId,
                    Path = resource.ResourceUrl,
                    Title = note.Subject,
                    AttachmentType = resource.FileExtension
                };
                db.Attachments.Add(attachment);
            }

            db.SaveChanges();
        }
        public IHttpActionResult createNewNote(CorrespondenceNoteBindingModel message)
        {
            if (message != null && ModelState.IsValid)
            {

                if (User.IsInRole(AuthorizationRoles.Role_Adviser))
                {
                    var adviser = edisRepo.GetAdviserSync(message.adviserNumber, DateTime.Now);
                    if (adviser == null || adviser.AdviserNumber != User.Identity.GetUserId())
                    {
                        ModelState.AddModelError("", "Invalid adviser id supplied, or current adviser is trying to add note for another adviser, which is illegal.");
                        return BadRequest(ModelState);
                    }
                    #region make sure client cannot create notes
                    if (User.IsInRole(AuthorizationRoles.Role_Client) && message.noteTypeId == BusinessLayerParameters.noteType_note)
                    {
                        ModelState.AddModelError("", "Client cannot add self-note.");
                        return BadRequest(ModelState);
                    }
                    var senderRole = User.IsInRole(AuthorizationRoles.Role_Adviser) ?
                                            BusinessLayerParameters.correspondenceSenderRole_adviser
                                            : BusinessLayerParameters.correspondenceSenderRole_client;

                    #endregion

                    Message messageData = new Message(edisRepo) { 
                        adviserNumber = message.adviserNumber,
                        assetTypeId = message.assetTypeId,
                        body = message.body,
                        accountId = message.accountId,
                        clientId = message.clientId,
                        dateCompleted = message.dateCompleted,
                        dateDue = message.dateDue,
                        followupActions = message.followupActions,
                        followupDate = message.followupDate,
                        isAccepted = message.isAccepted,
                        isDeclined = message.isDeclined,
                        noteSerial = message.noteSerial,
                        noteTypeId = message.noteTypeId,
                        productTypeId = message.productTypeId,
                        reminder = message.reminder,
                        reminderDate = DateTime.Now,                    //need to be changed
                        resourceToken = message.resourceToken,
                        status = message.status,
                        subject = message.subject,
                        timespent = message.timespent
                    };

                    edisRepo.CreateNewMessageSync(messageData, senderRole);

                }


                return Ok();


            }
            else
            {
                if (message == null)
                {
                    ModelState.AddModelError("", "Model is not provided");
                }
                return BadRequest(ModelState);
            }
        }