Exemplo n.º 1
0
        public OperationResult UpdateInvoice(InvoiceUpdate invoiceCreateRequest, Guid processId)
        {
            OperationResult responseObject = new OperationResult();

            try
            {
                InvoiceUpdate invoiceCreateProperties = invoiceCreateRequest;

                if (invoiceCreateProperties != null)
                {
                    JObject invoiceUpdateObject = this.GetUpdateInvoiceJsonStructure(invoiceCreateProperties, processId);


                    responseObject = this.InvoiceUpdateRequest(invoiceUpdateObject, invoiceCreateRequest.idFromDatabase, processId);
                }
            }
            catch (Exception ex)
            {
                LogEventInfo log = new LogEventInfo(LogLevel.Error, Logger.Name, null, "", null, new Exception(ex.ToString()));
                log.Properties["ProcessID"]  = processId;
                log.Properties["AppID"]      = AboxDynamicsBase.Classes.Constants.ApplicationIdWebAPI;
                log.Properties["MethodName"] = System.Reflection.MethodBase.GetCurrentMethod().Name;
                Logger.Log(log);

                //Logger.Error(ex,"");
                responseObject.Code         = "";
                responseObject.Message      = ex.ToString();
                responseObject.IsSuccessful = false;
                responseObject.Data         = null;
            }

            return(responseObject);
        }
Exemplo n.º 2
0
        public async Task <ActionResult <IInvoiceView> > Update([FromRoute] int id, [FromBody] InvoiceUpdate invoiceUpdate)
        {
            try
            {
                var grain  = _orleansService.Client.GetGrain <InvoiceUpdateCommand>(0);
                var result = await grain.InvoiceUpdate(invoiceUpdate);

                if (result.__CQRSSuccessful)
                {
                    return(new ActionResult <IInvoiceView>(result));
                }
                else
                {
                    return(new ContentResult()
                    {
                        StatusCode = result.__CQRSStatusCode, Content = result.__CQRSErrorMessage, ContentType = "text/plain"
                    });
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLogger().Log(LogLevel.Error, e);
                return(new ContentResult()
                {
                    StatusCode = 500, Content = "Fatal API Error", ContentType = "text/plain"
                });
            }
        }
Exemplo n.º 3
0
        public async Task <OperationResult <InvoiceDetails> > UpdateInvoice(InvoiceUpdate invoiceUpdate, CancellationToken cancellationToken)
        {
            var result  = new OperationResult <InvoiceDetails>();
            var invoice = _unitOfWork.GetRepository <Invoice>().Find(t => t.InvoiceId == invoiceUpdate.InvoiceId);

            if (invoice == null)
            {
                result.NotFound = true;
                return(result);
            }
            try
            {
                _unitOfWork.BeginTransaction();
                var updatedInvoice = _mapper.Map <InvoiceUpdate, Invoice>(invoiceUpdate);
                _unitOfWork.GetRepository <Invoice>().Update(updatedInvoice);
                _unitOfWork.SaveChanges();
                _unitOfWork.Commit();
                result.Entity = _mapper.Map <Invoice, InvoiceDetails>(updatedInvoice);
            }
            catch (Exception)
            {
                _unitOfWork.Rollback();
                result.Errors.Add("ServerErrorMessage", "Server error occurred");
                throw;
            }
            return(result);
        }
Exemplo n.º 4
0
        public async Task <data.Invoice> Update(data.InvoiceContext db, InvoiceUpdate update)
        {
            try
            {
                var invoiceToUpdate = await db.Invoices.FirstOrDefaultAsync(w => w.InvoiceId == update.InvoiceId);

                invoiceToUpdate.BillingAddress     = update.BillingAddress;
                invoiceToUpdate.CreatedDate        = update.CreatedDate;
                invoiceToUpdate.DueDate            = update.DueDate;
                invoiceToUpdate.EmailTo            = update.EmailTo;
                invoiceToUpdate.GrandTotal         = update.GrandTotal;
                invoiceToUpdate.InvoiceEmailed     = update.InvoiceEmailed;
                invoiceToUpdate.InvoiceId          = update.InvoiceId;
                invoiceToUpdate.InvoiceNo          = update.InvoiceNo;
                invoiceToUpdate.Notes              = update.Notes;
                invoiceToUpdate.OrderedBy          = update.OrderedBy;
                invoiceToUpdate.PaidAmount         = update.PaidAmount;
                invoiceToUpdate.PaidDate           = update.PaidDate;
                invoiceToUpdate.PaidTax            = update.PaidTax;
                invoiceToUpdate.PaymentDetails     = update.PaymentDetails;
                invoiceToUpdate.PurchaseOrderRef   = update.PurchaseOrderRef;
                invoiceToUpdate.ShippingAddress    = update.ShippingAddress;
                invoiceToUpdate.SubTotal           = update.SubTotal;
                invoiceToUpdate.TaxTotal           = update.TaxTotal;
                invoiceToUpdate.TermsAndConditions = update.TermsAndConditions;
                return(invoiceToUpdate);
            }
            catch (Exception e)
            {
                LogFactory.GetLogger().Log(LogLevel.Error, e);
                return(null);
            }
        }
Exemplo n.º 5
0
        public void InvoiceLineUpdateTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <update_invoice key=""1234"">
        <updateinvoiceitems>
            <updatelineitem line_num=""1"">
                <memo>hello world</memo>
            </updatelineitem>
        </updateinvoiceitems>
    </update_invoice>
</function>";

            InvoiceUpdate record = new InvoiceUpdate("unittest")
            {
                RecordNo = 1234,
            };

            InvoiceLineUpdate line1 = new InvoiceLineUpdate()
            {
                LineNo = 1,
                Memo   = "hello world"
            };

            record.Lines.Add(line1);

            this.CompareXml(expected, record);
        }
        public IHttpActionResult Update([FromBody] InvoiceUpdate invoiceUpdateRequest)
        {
            Guid processId = Guid.NewGuid();

            LogEventInfo log = new LogEventInfo(LogLevel.Debug, Logger.Name, $"ProcessID: {processId} Request hacia {Request.RequestUri} con el JSON:**START** {JsonConvert.SerializeObject(invoiceUpdateRequest)} **END**");

            log.Properties["ProcessID"]  = processId;
            log.Properties["AppID"]      = AboxDynamicsBase.Classes.Constants.ApplicationIdWebAPI;
            log.Properties["MethodName"] = System.Reflection.MethodBase.GetCurrentMethod().Name;
            Logger.Log(log);

            EInvoice        invoiceProcedures = new EInvoice();
            OperationResult response          = null;

            try
            {
                if (invoiceUpdateRequest != null)
                {
                    response = invoiceProcedures.UpdateInvoice(invoiceUpdateRequest, processId);

                    if (response.IsSuccessful)
                    {
                        return(Ok(response));
                    }
                    else
                    {
                        return(Content(HttpStatusCode.InternalServerError, response));
                    }
                }
                else
                {
                    return(Content(HttpStatusCode.BadRequest, new OperationResult
                    {
                        Code = "",
                        IsSuccessful = false,
                        Data = null,
                        Message = "La solicitud JSON enviada es incorrecta"
                    }));
                }
            }
            catch (Exception ex)
            {
                LogEventInfo logEx = new LogEventInfo(LogLevel.Error, Logger.Name, null, $"Request hacia {Request.RequestUri} con el JSON:**START** {JsonConvert.SerializeObject(invoiceUpdateRequest)} **END**", null, new Exception(ex.ToString()));
                logEx.Properties["ProcessID"]  = processId;
                logEx.Properties["AppID"]      = Constants.ApplicationIdWebAPI;
                logEx.Properties["MethodName"] = System.Reflection.MethodBase.GetCurrentMethod().Name;
                Logger.Log(logEx);

                return(Content(HttpStatusCode.InternalServerError, new OperationResult
                {
                    IsSuccessful = false,
                    Data = null,
                    Message = ex.ToString(),
                    Code = ""
                }));
            }
        }
Exemplo n.º 7
0
        public void GetXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <update_invoice key=""1234"" />
</function>";

            InvoiceUpdate record = new InvoiceUpdate("unittest")
            {
                RecordNo = 1234,
            };

            this.CompareXml(expected, record);
        }
Exemplo n.º 8
0
// Update Transaction Code
        public async Task <InvoiceView> Update(InvoiceUpdate update)
        {
            try
            {
                using (var db = new data.InvoiceContext())
                {
                    var result = await Update(db, update);

                    await db.SaveChangesAsync();

                    return((InvoiceView)result);
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLogger().Log(LogLevel.Error, e);
                return(null);
            }
        }
        public async Task <InvoiceView> InvoiceUpdate(InvoiceUpdate update)
        {
            try
            {
                string json = "";

                var client = new HttpClient();

                using (var ms = new MemoryStream())
                {
                    var serializer = new DataContractJsonSerializer(typeof(InvoiceUpdate), new DataContractJsonSerializerSettings()
                    {
                        DateTimeFormat = new DateTimeFormat("yyyy-MM-dd'T'HH:mm:ss")
                    });
                    serializer.WriteObject(ms, update);
                    ms.Position = 0;
                    StreamReader sr = new StreamReader(ms);
                    json = sr.ReadToEnd();
                }

                var stream = await client.PutAsync($"http://localhost:44443/api/invoice/{update.InvoiceId}", new StringContent(json, Encoding.UTF8, "application/json"));

                using (var ms = new MemoryStream())
                {
                    var serializer = new DataContractJsonSerializer(typeof(InvoiceView));
                    await stream.Content.CopyToAsync(ms);

                    ms.Position = 0;
                    var view = serializer.ReadObject(ms) as InvoiceView;
                    return(view);
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLogger().Log(LogLevel.Error, e);
                return(null);
            }
        }
Exemplo n.º 10
0
        public InvoiceUpdate GetInvoiceUpdate()
        {
            var result = new InvoiceUpdate();

            result.CreatedDate        = InvoiceView.CreatedDate;
            result.DueDate            = InvoiceView.DueDate;
            result.EmailTo            = InvoiceView.EmailTo;
            result.GrandTotal         = InvoiceView.GrandTotal;
            result.InvoiceEmailed     = InvoiceView.InvoiceEmailed;
            result.InvoiceId          = InvoiceView.InvoiceId;
            result.InvoiceNo          = InvoiceView.InvoiceNo;
            result.Notes              = InvoiceView.Notes;
            result.OrderedBy          = InvoiceView.OrderedBy;
            result.PaidAmount         = InvoiceView.PaidAmount;
            result.PaidDate           = InvoiceView.PaidDate;
            result.PaidTax            = InvoiceView.PaidTax;
            result.PaymentDetails     = InvoiceView.PaymentDetails;
            result.PurchaseOrderRef   = InvoiceView.PurchaseOrderRef;
            result.Status             = InvoiceView.Status;
            result.SubTotal           = InvoiceView.SubTotal;
            result.TaxTotal           = InvoiceView.TaxTotal;
            result.TermsAndConditions = InvoiceView.TermsAndConditions;
            return(result);
        }
Exemplo n.º 11
0
        private JObject GetUpdateInvoiceJsonStructure(InvoiceUpdate invoiceProperties, Guid processId)
        {
            OperationResult result        = new OperationResult();
            JObject         jObject       = new JObject();
            CountryEntity   countryEntity = new CountryEntity();

            try
            {
                if (invoiceProperties != null)
                {
                    if (invoiceProperties.billDate != null)
                    {
                        DateTime date = DateTime.Parse(invoiceProperties.billDate);
                        jObject.Add($"{InvoiceFields.PurchaseDate}", date.ToString("yyyy-MM-dd"));
                    }

                    if (invoiceProperties.patientId > 0)
                    {
                        jObject.Add($"{InvoiceSchemas.CustomerIdSchema}@odata.bind", $"/{contactEntity.EntityPluralName}({ContactFields.IdAboxPatient}={invoiceProperties.patientId})");
                    }

                    if (invoiceProperties.patientId > 0)
                    {
                        jObject.Add($"{InvoiceSchemas.CustomerContactSchema}@odata.bind", $"/{contactEntity.EntityPluralName}({ContactFields.IdAboxPatient}={invoiceProperties.patientId})");
                    }


                    if (!(String.IsNullOrEmpty(invoiceProperties.billImageUrl)))
                    {
                        jObject.Add(InvoiceFields.InvoiceImageWebUrl, invoiceProperties.billImageUrl);
                    }



                    if (!(String.IsNullOrEmpty(invoiceProperties.pharmacyId)))
                    {
                        jObject.Add($"{InvoiceSchemas.Pharmacy}@odata.bind", $"/{pharmacyEntity.EntityPluralName}({PharmacyFields.Id}='{invoiceProperties.pharmacyId}')");
                    }

                    if (!(String.IsNullOrEmpty(invoiceProperties.billId)))
                    {
                        jObject.Add(InvoiceFields.InvoiceNumber, invoiceProperties.billId);
                    }


                    if (invoiceProperties.products != null)
                    {
                        var serialized = JsonConvert.SerializeObject(invoiceProperties.products);
                        jObject.Add($"{InvoiceFields.ProductsSelectedJson}", serialized);
                    }

                    if (invoiceProperties.nonAboxProducts != null)
                    {
                        var serialized = JsonConvert.SerializeObject(invoiceProperties.nonAboxProducts);
                        jObject.Add($"{InvoiceFields.NonAboxProductsSelectedJson}", serialized);
                    }



                    if (!(String.IsNullOrEmpty(invoiceProperties.country)))
                    {
                        jObject.Add($"{InvoiceSchemas.Country}@odata.bind", $"/{countryEntity.EntityPluralName}({CountryFields.IdCountry}='{invoiceProperties.country}')");
                    }

                    if (!String.IsNullOrEmpty(invoiceProperties.status))
                    {
                        int status = sharedMethods.GetInvoiceStatusValue(invoiceProperties.status);
                        if (status > -1)
                        {
                            jObject.Add(InvoiceFields.StatusCode, status);
                        }
                    }

                    if (!String.IsNullOrEmpty(invoiceProperties.statusReason))
                    {
                        jObject.Add(InvoiceFields.StatusReason, invoiceProperties.statusReason);
                    }

                    if (invoiceProperties.revisionTime1 != null && invoiceProperties.revisionTime1 > -1)
                    {
                        jObject.Add(InvoiceFields.RevisionTime1, invoiceProperties.revisionTime1);
                    }

                    if (invoiceProperties.revisionTime2 != null && invoiceProperties.revisionTime2 > -1)
                    {
                        jObject.Add(InvoiceFields.RevisionTime2, invoiceProperties.revisionTime2);
                    }

                    if (invoiceProperties.totalAmount != null)
                    {
                        jObject.Add(InvoiceFields.TotalAmount, invoiceProperties.totalAmount);
                    }

                    if (!String.IsNullOrEmpty(invoiceProperties.purchaseMethod))
                    {
                        jObject.Add(InvoiceFields.PurchaseMethod, invoiceProperties.purchaseMethod);
                    }


                    ////////////
                }

                return(jObject);
            }
            catch (Exception ex)
            {
                LogEventInfo log = new LogEventInfo(LogLevel.Error, Logger.Name, null, "", null, new Exception(ex.ToString()));
                log.Properties["ProcessID"]  = processId;
                log.Properties["AppID"]      = AboxDynamicsBase.Classes.Constants.ApplicationIdWebAPI;
                log.Properties["MethodName"] = System.Reflection.MethodBase.GetCurrentMethod().Name;
                Logger.Log(log);
                jObject = null;
                return(jObject);
            }
        }
Exemplo n.º 12
0
        public void GetAllXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <update_invoice key=""20394"" externalkey=""true"">
        <customerid>CUSTOMER1</customerid>
        <datecreated>
            <year>2015</year>
            <month>06</month>
            <day>30</day>
        </datecreated>
        <dateposted>
            <year>2015</year>
            <month>06</month>
            <day>30</day>
        </dateposted>
        <datedue>
            <year>2020</year>
            <month>09</month>
            <day>24</day>
        </datedue>
        <termname>N30</termname>
        <action>Submit</action>
        <invoiceno>234</invoiceno>
        <ponumber>234235</ponumber>
        <description>Some description</description>
        <payto>
            <contactname>28952</contactname>
        </payto>
        <returnto>
            <contactname>289533</contactname>
        </returnto>
        <currency>USD</currency>
        <exchratedate>
            <year>2015</year>
            <month>06</month>
            <day>30</day>
        </exchratedate>
        <exchratetype>Intacct Daily Rate</exchratetype>
        <supdocid>6942</supdocid>
        <customfields>
            <customfield>
                <customfieldname>customfield1</customfieldname>
                <customfieldvalue>customvalue1</customfieldvalue>
            </customfield>
        </customfields>
        <updateinvoiceitems>
            <updatelineitem line_num=""1"">
                <amount>1000</amount>
            </updatelineitem>
            <lineitem>
                <glaccountno />
                <amount>76343.43</amount>
            </lineitem>
        </updateinvoiceitems>
    </update_invoice>
</function>";

            InvoiceUpdate record = new InvoiceUpdate("unittest")
            {
                RecordNo            = 1234,
                CustomerId          = "CUSTOMER1",
                TransactionDate     = new DateTime(2015, 06, 30),
                GlPostingDate       = new DateTime(2015, 06, 30),
                DueDate             = new DateTime(2020, 09, 24),
                PaymentTerm         = "N30",
                Action              = "Submit",
                InvoiceNumber       = "234",
                ReferenceNumber     = "234235",
                Description         = "Some description",
                ExternalId          = "20394",
                BillToContactName   = "28952",
                ShipToContactName   = "289533",
                TransactionCurrency = "USD",
                ExchangeRateDate    = new DateTime(2015, 06, 30),
                ExchangeRateType    = "Intacct Daily Rate",
                AttachmentsId       = "6942",
                CustomFields        = new Dictionary <string, dynamic>
                {
                    { "customfield1", "customvalue1" }
                },
            };

            InvoiceLineUpdate line1 = new InvoiceLineUpdate
            {
                LineNo            = 1,
                TransactionAmount = 1000
            };

            record.Lines.Add(line1);

            InvoiceLineCreate line2 = new InvoiceLineCreate
            {
                TransactionAmount = 76343.43M
            };

            record.Lines.Add(line2);

            this.CompareXml(expected, record);
        }
 public async Task<InvoiceUpdate.response> InvoiceUpdate(InvoiceUpdate.request request, CancellationToken? token = null)
 {
     return await SendAsync<InvoiceUpdate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
Exemplo n.º 14
0
 public async Task <IActionResult> UpdateInvoice([FromBody] InvoiceUpdate invoiceUpdate, Guid id, CancellationToken cancellationToken)
 {
     return(id != invoiceUpdate.InvoiceId ? NotFound($"The Id '{id}' passed by parameter is different from the Id '{invoiceUpdate.InvoiceId}' on request body")
         : Resolve(await _invoiceService.UpdateInvoice(invoiceUpdate, cancellationToken), HttpStatusCode.Created));
 }