// POST: api/PreviewFax
        public string Post([FromBody] Fax faxValues)
        {
            string documentList = faxValues.DocumentList;
            string faxTo = faxValues.FaxTo;
            string notes = faxValues.Notes;
            string cover = faxValues.Cover;
            string from = faxValues.From;
            string faxPath = string.Empty;
            string[] faxes = documentList.Split('~');
            string permanentFaxPath = string.Empty;

            Misc misc = new Misc();

            try
            {
                FaxingInformation faxingInformationInitial  = new Models.FaxingInformation();

                faxingInformationInitial.DocumentList = documentList;

                faxingInformationInitial.DocumentList = documentList;
                faxingInformationInitial.FaxTo = faxTo;
                faxingInformationInitial.Notes = notes;
                faxingInformationInitial.From = from;
                faxingInformationInitial.Cover = cover;

                FaxingInformation miscFaxInformation = misc.CreateFax(faxingInformationInitial);
                faxPath = ConfigurationValues.PdfFolder + miscFaxInformation.NameFromDateTimeString;
                System.IO.File.Copy(miscFaxInformation.FaxPath,
                    ConfigurationValues.WhereToCopyPDfTo + miscFaxInformation.NameFromDateTimeString, true);
                System.IO.File.Delete(miscFaxInformation.FaxPath);
                return faxPath;
            }
            catch (Exception er)
            {
                string s1 = er.ToString();
                return faxPath;
            }
        }
        // POST: api/SendFax
        public IHttpActionResult Post([FromBody] Fax faxValues)
        {
            OperationResult createFaxRecordOperationResult = new Models.OperationResult();
            OperationResult sendFaxToMultiTechOperationResult = new Models.OperationResult();
            
            FaxData faxData = new FaxData();

            string documentList = faxValues.DocumentList;
            string faxTo = faxValues.FaxTo;
            string notes = faxValues.Notes;
            string cover = faxValues.Cover;
            string from = faxValues.From;

            string faxPath = string.Empty;
            string[] faxes = faxTo.Split('~');
            string permanentFaxPath = string.Empty;

            Misc misc = new Misc();

            try
            {
                for (int i = 0; i < faxes.Length - 1; i++)
                {
                    FaxingInformation faxingInformatonInitial = new FaxingInformation();

                    faxingInformatonInitial.DocumentList = documentList;
                    faxingInformatonInitial.FaxTo = faxes[i];
                    faxingInformatonInitial.Notes = notes;
                    faxingInformatonInitial.From = from;
                    faxingInformatonInitial.Cover = cover;

                    FaxingInformation faxingInformatonComplete = misc.CreateFax(faxingInformatonInitial);

                    permanentFaxPath = Walden.CompleteFax.Library.Database.PernamentFaxPath
                            + Utility.GetUserName() + "\\" + faxingInformatonComplete.NameFromDateTimeString;

                    System.IO.File.Copy(ConfigurationValues.TemporaryFaxPath
                        + Utility.GetUserName() + "\\" + faxingInformatonComplete.NameFromDateTimeString,
                        ConfigurationValues.PernamentFaxPath
                        + faxingInformatonComplete.NameFromDateTimeString, true);

                    string now = DateTime.Now.ToShortDateString()
                        + " "
                        + DateTime.Now.ToShortTimeString();

                    createFaxRecordOperationResult = faxData.SendFax(faxingInformatonComplete, ConfigurationValues.PernamentFaxPath
                        + faxingInformatonComplete.NameFromDateTimeString, from, notes);

                    if (createFaxRecordOperationResult.Success)
                    {
                        sendFaxToMultiTechOperationResult = sendFaxMultitech.SendTheFax(faxingInformatonComplete.Name, faxingInformatonComplete.FaxPath,
                            from, faxingInformatonComplete.FaxNumber, createFaxRecordOperationResult.MessageList[0], ConfigurationValues.ApplicationPath);
                        if (sendFaxToMultiTechOperationResult.Success)
                        {
                            System.IO.File.Delete(ConfigurationValues.TemporaryFaxPath
                                + Utility.GetUserName()
                                + "\\" + faxingInformatonComplete.NameFromDateTimeString);
                        }
                        else
                        {
                            faxData.UpdateFaxRecord(createFaxRecordOperationResult.MessageList[0]);
                        }
                    }
                    else
                    {
                        return BadRequest(createFaxRecordOperationResult.ErrorMessage);
                    }
                }
            }
            catch (Exception er)
            {
                return InternalServerError(er);
            }

            string[] faxesToDelete = documentList.Split('~');

            for (int i = 0; i < faxesToDelete.Length - 1; i++)
            {
                System.IO.File.Delete(ConfigurationValues.TemporaryFaxPath
                    + Utility.GetUserName() + "\\"
                    + faxesToDelete[i]);
            }

            return Ok();
        }