public IActionResult Create(ExpenseLimit expenseLimit)
 {
     if (ModelState.IsValid)
     {
         if (string.IsNullOrEmpty(User.Identity.Name))
         {
             userName = "******";
         }
         else
         {
             userName = User.Identity.Name;
         }
         IEnumerable <ExpenseLimit> expenseLimits = _expenseLimitRepository.GetExpenseLimitsAll(userName);
         var result = expenseLimits.SingleOrDefault(el => el.ExpenseType == expenseLimit.ExpenseType);
         if (result == null)
         {
             expenseLimit.UserName = userName;
             ExpenseLimit newexpenseLimit = _expenseLimitRepository.Add(expenseLimit);
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", $"Limit already exists for {expenseLimit.ExpenseType}");
         }
     }
     return(View());
 }
Exemple #2
0
        public async void UpdateExpenseLimit(ExpenseLimit expenseLimit)
        {
            try
            {
                var docRef          = firestore.Collection("expenseLimits").Document(expenseLimit.Id);
                var startDateString = expenseLimit.StartDate.Year.ToString() + "-" + (expenseLimit.StartDate.Month < 10 ? "0" + expenseLimit.StartDate.Month.ToString() : expenseLimit.StartDate.Month.ToString()) + "-" + (expenseLimit.StartDate.Day < 10 ? "0" + expenseLimit.StartDate.Day.ToString() : expenseLimit.StartDate.Day.ToString());
                var endDateString   = expenseLimit.EndDate.Year.ToString() + "-" + (expenseLimit.EndDate.Month < 10 ? "0" + expenseLimit.EndDate.Month.ToString() : expenseLimit.EndDate.Month.ToString()) + "-" + (expenseLimit.EndDate.Day < 10 ? "0" + expenseLimit.EndDate.Day.ToString() : expenseLimit.EndDate.Day.ToString());

                await docRef.SetAsync(new { Name = expenseLimit.Name, CategoryId = expenseLimit.CategoryId, OwnerId = expenseLimit.OwnerId, Amount = expenseLimit.Amount, StartDate = startDateString, EndDate = endDateString }, SetOptions.Overwrite);
            }
            catch (Exception)
            {
                Console.WriteLine("Något gick fel");
            }
        }
Exemple #3
0
        public ActionResult Edit(ExpenseLimit expenseLimit)
        {
            if (ModelState.IsValid)
            {
                ExpenseTrackerIdentity ident = User.Identity as ExpenseTrackerIdentity;
                expenseLimit.CreatedBy = ident.UserId;
                var data = _expenseLimitService.Update(expenseLimit);
                ShowStatus(data.StatusCode, data.Status);
                if (data.StatusCode == 200)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }
            }

            return(View(expenseLimit));
        }
Exemple #4
0
 public ActionResult Create(ExpenseLimit expense)
 {
     if (ModelState.IsValid)
     {
         ExpenseTrackerIdentity ident = User.Identity as ExpenseTrackerIdentity;
         expense.Status    = true;
         expense.CreatedBy = ident.UserId;
         var msg = _expenseLimitService.Create(expense);
         ShowStatus(msg.StatusCode, msg.Status);
         if (msg.StatusCode == 200)
         {
             return(RedirectToAction("Index", "Dashboard"));
         }
     }
     return(View());
 }
 public IActionResult Edit(ExpenseLimit expenseLimit)
 {
     if (ModelState.IsValid)
     {
         if (string.IsNullOrEmpty(User.Identity.Name))
         {
             userName = "******";
         }
         else
         {
             userName = User.Identity.Name;
         }
         expenseLimit.UserName = userName;
         ExpenseLimit updatedexpenseLimit = _expenseLimitRepository.Update(expenseLimit);
         return(RedirectToAction("Index"));
     }
     return(View(expenseLimit));
 }
Exemple #6
0
        public Message Create(ExpenseLimit expenseLimit)
        {
            Message msg = new Message();

            try
            {
                var model = expenseLimit.ToDalEntity();
                _expenseLimitRepository.Add(model);
                _expenseLimitRepository.SaveChanges();
                msg.StatusCode = 200;
                msg.Status     = "Expense limit has been added successfully. You will be notified when you expend more than your Limit";
            }
            catch (Exception ex)
            {
                msg.StatusCode = 400;
                msg.Status     = "An error occured while creating expense limit.";
            }

            return(msg);
        }
        public ViewResult Edit(int Id)
        {
            if (string.IsNullOrEmpty(User.Identity.Name))
            {
                userName = "******";
            }
            else
            {
                userName = User.Identity.Name;
            }
            ExpenseLimit expenseLimit = _expenseLimitRepository.GetExpenseLimitById(Id, userName);

            if (expenseLimit == null)
            {
                Response.StatusCode  = 404;
                ViewBag.ErrorMessage = $"ExpenseLimit with Id = {Id} cannot be found";
                return(View("NotFound"));
            }
            return(View(expenseLimit));
        }
Exemple #8
0
        public Message Update(ExpenseLimit expenseLimit)
        {
            var msg = new Message();

            try
            {
                var model = _expenseLimitRepository.FindBy(x => x.CreatedBy == expenseLimit.CreatedBy).FirstOrDefault();
                if (model == null)
                {
                    throw new ArgumentException();
                }
                expenseLimit.ToDalEntity(model);
                _expenseLimitRepository.Edit(model);
                _expenseLimitRepository.SaveChanges();
                msg.StatusCode = 200;
                msg.Status     = "Expense Limit Updated Successfully";
            }
            catch (Exception ex)
            {
                msg.StatusCode = 400;
                msg.Status     = "An error occured while creating expense limit.";
            }
            return(msg);
        }
Exemple #9
0
 public void Put([FromBody] ExpenseLimit expenseLimit)
 {
     firestore.UpdateExpenseLimit(expenseLimit);
 }
Exemple #10
0
 public void Post([FromBody] ExpenseLimit expenseLimit)
 {
     firestore.AddExpenseLimit(expenseLimit);
 }