コード例 #1
0
        public Invoice CreateInvoice(InvoiceForCreationDto inputInvoice)
        {
            // determine current New Zealand time
            TimeZoneInfo tz       = TimeZoneInfo.FindSystemTimeZoneById("New Zealand Standard Time");
            DateTime     localNow = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz);

            // copy information provided by the client
            Invoice invoice = mapper.Map <Invoice>(inputInvoice);

            invoice.InvoiceNumber   = GenerateOrganisationInvoiceNumber(inputInvoice.LoginId);
            invoice.CharitiesNumber = options.CharitiesNumber;
            invoice.GstNumber       = options.GSTNumber;
            invoice.GstRate         = options.GSTRate;
            invoice.DateCreated     = localNow;
            invoice.Status          = InvoiceStatus.Draft;
            invoice.Creator         = context.User.FirstOrDefault(u => u.Email == inputInvoice.LoginId);

            Validate(invoice);

            context.Add <Invoice>(invoice);
            int count = context.SaveChanges();

            if (count > 0)
            {
                return(invoice);
            }
            else
            {
                return(null);
            }
        }