コード例 #1
0
 public ActionResult StartWorkout(EntriesViewModel view)
 {
     if (ModelState.IsValid)
     {
         var entryrepo = new EntryRepository();
         var entry     = new Entries()
         {
             EntryNo = view.EntryNo, Workout_id = view.Workout_id, start_date = view.start_date, start_time = view.start_time, entry_status = "inprogress"
         };
         var isAdded = entryrepo.Add(entry);
         if (isAdded)
         {
             return(RedirectToAction(""));
         }
         else
         {
             ModelState.AddModelError("", "Failed to add");
             return(View(view));
         }
     }
     else
     {
         ModelState.AddModelError("", "One or more validations failed");
         return(View(view));
     }
 }
コード例 #2
0
        public static Func <IRequest, IResponse> LogAdd(EntryRepository Repo)
        {
            return((IRequest Request) => {
                if (string.IsNullOrWhiteSpace(Request.Body))
                {
                    return Status(400, "no data");
                }

                Entry e = null;
                try {
                    e = (Entry)JsonSerializer.Create().Deserialize(new System.IO.StringReader(Request.Body), typeof(Entry));
                } catch (Exception ex) {
                    return Status(400, "invalid input", ex.Message);
                }

                Repo.Add(e);

                return OK();
            });
        }
コード例 #3
0
        /// <summary>
        /// Import from Hibiscus CSV file.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="eventArgs">The event args.</param>
        private void ImportFromHibiscus_Click(object sender, RoutedEventArgs eventArgs)
        {
            var fileDialog = new Microsoft.Win32.OpenFileDialog()
            {
                RestoreDirectory = true,
                Filter           = "Hibiscus CSV File (*.csv)|*.csv|Hibiscus XML File (*.xml)|*.xml",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
            };

            var filePath = string.Empty;

            if (fileDialog.ShowDialog() == true)
            {
                filePath = fileDialog.FileName;
            }

            if (!string.IsNullOrEmpty(filePath))
            {
                if (filePath.ToLowerInvariant().EndsWith(".csv"))
                {
                    var csvContents = FileHelper.StreamFromFile(filePath);

                    var csvData = CsvHelper.TableFromCsvStream(
                        csvContents,
                        containsHeaders: true,
                        delimiter: ';',
                        lineSeparator: "\n",
                        encoding: Encoding.GetEncoding("ISO-8859-1"));

                    var repository = new EntryRepository();

                    foreach (DataRow row in csvData.Rows)
                    {
                        var entry = new Entry()
                        {
                            Amount = Convert.ToDecimal(row[7]),
                            AdditionalInformation = string.Format(
                                "Purpose 01: {0}\r\nPurpose 02: {1}\r\nPurpose 03: {2}\r\nNote: {3}",
                                row[10],
                                row[11],
                                row[17],
                                row[16]),
                            Date        = Convert.ToDateTime(row[9]),
                            ValueDate   = Convert.ToDateTime(row[8]),
                            Type        = row[18].ToString(),
                            Description = row[10].ToString(),
                        };

                        entry.Account = this.FindOrCreateAccount(
                            name: row[3].ToString(),
                            bic: row[2].ToString(),
                            iban: row[1].ToString());

                        entry.CounterAccount = this.FindOrCreateAccount(
                            name: row[6].ToString(),
                            bic: row[5].ToString(),
                            iban: row[4].ToString());

                        entry.Category = this.FindOrCreateCategory(
                            name: row[15].ToString());

                        repository.Add(entry);
                    }
                }
                else if (filePath.ToLowerInvariant().EndsWith(".xml"))
                {
                    var xmlContents = XElement.Load(filePath);

                    var repository = new EntryRepository();

                    foreach (var xmlObject in xmlContents.Elements("object"))
                    {
                        var entry = new Entry()
                        {
                            Amount = Convert.ToDecimal(xmlObject.Element("betrag")?.Value),
                            AdditionalInformation = string.Format(
                                "Purpose 01: {0}\r\nPurpose 02: {1}\r\nPurpose 03: {2}\r\nNote: {3}",
                                xmlObject.Element("zweck")?.Value,
                                xmlObject.Element("zweck2")?.Value,
                                xmlObject.Element("zweck3")?.Value,
                                xmlObject.Element("kommentar")?.Value),
                            Date        = Convert.ToDateTime(xmlObject.Element("datum")?.Value),
                            ValueDate   = Convert.ToDateTime(xmlObject.Element("valuta")?.Value),
                            Type        = xmlObject.Element("umsatztyp_id")?.Value,
                            Description = xmlObject.Element("zweck")?.Value,
                        };

                        entry.Account = this.FindOrCreateAccount(
                            name: string.Format("Own Account {0:000}", Convert.ToInt32(xmlObject.Element("konto_id")?.Value)),
                            bic: string.Empty,
                            iban: string.Empty);

                        entry.CounterAccount = this.FindOrCreateAccount(
                            name: string.Format("{0} {1}", xmlObject.Element("empfaenger_name")?.Value, xmlObject.Element("empfaenger_name2")?.Value),
                            bic: xmlObject.Element("empfaenger_blz")?.Value,
                            iban: xmlObject.Element("empfaenger_konto")?.Value);

                        repository.Add(entry);
                    }
                }
            }
        }
コード例 #4
0
        public void Add_new_item_to_Repository_return_true()
        {
            repo.Add(Helper.makeEntry());

            Assert.AreEqual(1, repo.Count());
        }