/// <summary> /// Adds a <see cref="Share"/> to the database, /// also adds a new <see cref="ShareValue"/> for today to the database. /// </summary> /// <param name="share">The <see cref="Share"/> to add.</param> /// <param name="path">The path to the database to insert the <see cref="Share"/>into.</param> /// <returns>1 if successful, 0 if a share matching the ISIN already exists, -1 if an error occured.</returns> public static short AddShareToDB(AddShareViewModel share, string path = DEFAULTPATH) { try { // connect to the database using (SQLiteConnection con = new SQLiteConnection(path)) { // get the required tables of the database con.CreateTable <Share>(); con.CreateTable <ShareValue>(); // check if the share is lready in the database... if (con.Find <Share>(share.ISIN) == null) { // ... if not, add it to the tables var shareType = share.IsShare ? ShareType.Share : ShareType.Certificate; con.Insert(new Share(share.ShareName, share.WebSite, share.WKN, share.ISIN, shareType, share.WebSite2, share.WebSite3)); con.Insert(new ShareValue() { Date = DateTime.Now, ISIN = share.ISIN, Price = share.ActualPrice }); } else { return(0); } } return(1); } catch (Exception ex) { Logger.Log("AddShareToDB : " + ex.Message); return(-1); } }
public ActionResult Add(AddShareViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } var result = SaveAs(vm.Image, PlatformConfiguration.SharesPath); if (result == null) { return(View(vm)); } Command.Execute(new AddShareCommand { Title = vm.Title, Description = vm.Description, EndDate = vm.EndDate, RibbonColor = vm.RibbonColor, RibbonText = vm.RibbonText, IsRibbonDisplayed = vm.IsRibbonDisplayed, FileId = result.File.Id }); return(RedirectToAction("Index")); }