예제 #1
0
 public ActionResult AddOrEdit(Spendings spend)
 {
     try
     {
         if (spend.ImageUpload != null)
         {
             string fileName  = Path.GetFileNameWithoutExtension(spend.ImageUpload.FileName);
             string extension = Path.GetExtension(spend.ImageUpload.FileName);
             fileName        = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
             spend.ImagePath = "~/AppFiles/Images/" + fileName;
             spend.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
         }
         using (CashJugDBEntities db = new CashJugDBEntities())
         {
             if (spend.ItemID == 0)
             {
                 db.Spendings.Add(spend);
                 db.SaveChanges();
             }
             else
             {
                 db.Entry(spend).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
         return(RedirectToAction("Index"));
         //return Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "Index", GetAllSpendings()), message = "Submitted successfully" }, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         return(Json(new { success = true, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
        /// <summary>
        /// Metoda dodająca rekord w tabeli Spendings
        /// </summary>
        /// <param name="spendings"></param>
        /// <returns></returns>
        public async Task <string> AddSpendings(Spendings spendings)
        {
            dbContext.Spendings.Add(spendings);
            await dbContext.SaveChangesAsync();

            Serilog.Log.Information($@"Dodano nowe wydatki!, User: {spendings.idUser}, Date: {spendings.Date}, Car: {spendings.CarID}");
            return(await Task.FromResult("OK"));
        }
        //ПОДУМАЙ КАК ОБЬЕДЕНИТЬ ЭТИ ДВА МЕТОДА!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        /// <summary>
        /// Добавить расход.
        /// </summary>
        /// <param name="spendingName">Название расхода.</param>
        /// <param name="amount">Объем расхода.</param>
        /// <param name="category">Категория расхода.</param>
        /// <param name="comment">Комментарий к расходу.</param>
        public void AddSpending(string spendingName, double amount, string category, string comment)
        {
            var spending = new Spending(spendingName, amount, category, comment);

            Spendings.Add(spending);
            this.CurrentAccount.AccountBalance -= amount;
            SaveData(spending);
        }
예제 #4
0
        public ActionResult AddOrEdit(int id = 0)
        {
            Spendings spend = new Spendings();

            if (id != 0)
            {
                using (CashJugDBEntities db = new CashJugDBEntities())
                {
                    spend = db.Spendings.Where(x => x.ItemID == id).FirstOrDefault <Spendings>();
                }
            }
            return(View(spend));
        }
예제 #5
0
 public ActionResult Delete(int id)
 {
     try
     {
         using (CashJugDBEntities db = new CashJugDBEntities())
         {
             Spendings spend = db.Spendings.Where(x => x.ItemID == id).FirstOrDefault <Spendings>();
             db.Spendings.Remove(spend);
             db.SaveChanges();
         }
         return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllSpendings()), message = "Deleted successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = true, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
예제 #6
0
        public async void Save()
        {
            IMongoDatabase             database   = DataContext.GetMongoDatabase(DataContext.DatabaseName);
            IMongoCollection <Journey> collection = database.GetCollection <Journey>("journeys");

            if (Id == ObjectId.Empty)
            {
                await collection.InsertOneAsync(this);
            }
            else
            {
                await collection.ReplaceOneAsync <Journey>(x => x.Id == Id, this);
            }

            Initial = new Journey(this);
            Bivouac.EndInit();
            BorderCrossing.EndInit();
            Events.ToList().ForEach(x => x.EndInit());
            Spendings.ToList().ForEach(x => x.EndInit());

            OnPropertyChanged("HasBeenChanged");
        }
        /// <summary>
        /// Показать расходы по категориям.
        /// </summary>
        /// <param name="category"> Категория расхода. </param>
        public void ShowActionsByCategory(string category)
        {
            List <Spending> spendingsByCategory = Spendings.FindAll(s => s.Category == category);
            List <Income>   incomesByCategory   = Incomes.FindAll(i => i.Category == category);

            if (spendingsByCategory.Count != 0)
            {
                spendingsByCategory.Sort((s1, s2) => DateTime.Compare(s1.DateAdded, s2.DateAdded));
                spendingsByCategory.ForEach(s => Console.WriteLine(s));
                Console.WriteLine();
            }
            else if (incomesByCategory.Count != 0)
            {
                incomesByCategory.Sort((s1, s2) => DateTime.Compare(s1.DateAdded, s2.DateAdded));
                incomesByCategory.ForEach(s => Console.WriteLine(s));
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("Категория пуста.");
            }
        }
예제 #8
0
 public Spendings PutSpendings([FromBody] Spendings spendings)
 {
     return(spendingsService.UpdateSpendings(spendings));
 }
예제 #9
0
 public async Task <String> AddSpending([FromBody] Spendings spendings)
 {
     return(await spendingsService.AddSpendings(spendings));
 }
 /// <summary>
 /// Metoda modyfikująca rekord w tabeli Spendings
 /// </summary>
 /// <param name="spendings"></param>
 /// <returns></returns>
 public Spendings UpdateSpendings(Spendings spendings)
 {
     dbContext.Entry(spendings).State = EntityState.Modified;
     dbContext.SaveChanges();
     return(spendings);
 }