public IActionResult Create( int accountID, int?categoryID = null, bool?isCredit = null, bool showCategorySelector = true, decimal remaining = 0) { var types = EntryType.Debit | EntryType.Credit | EntryType.Transfer; if (isCredit.HasValue) { types = !isCredit.Value ? EntryType.Debit | EntryType.Transfer : EntryType.Credit; } var typeSelectListItems = TypesSelectListItems(types, _accountList(accountID)); var model = new CreateEntryViewModel { AccountID = accountID, CategoryID = categoryID, Types = typeSelectListItems, Type = typeSelectListItems.Count() == 1 ? typeSelectListItems.Single().Value : null, MonthlyBudgets = MonthlyBudgetsSelectListItems(accountID), Categories = Enumerable.Empty <SelectListItem>(), Parties = PartiesSelectListItems(accountID), IsCredit = isCredit, ShowCategorySelector = showCategorySelector, Remaining = remaining }; return(View(model)); }
public ActionResult CreateTest(CreateEntryViewModel model, HttpPostedFileBase picUpload) { if (Request.IsAuthenticated && ModelState.IsValid) { var user = db.Users.Find(User.Identity.GetUserId()) as ApplicationUser; Entries aEntry = new Entries(); aEntry.Author = user; aEntry.text = model.Entries.text; aEntry.Heading = model.Entries.Heading; aEntry.Date = DateTime.Today; if (picUpload != null && picUpload.ContentLength > 0) { aEntry.Filename = picUpload.FileName; aEntry.ContentType = picUpload.ContentType; using (var reader = new BinaryReader(picUpload.InputStream)) { aEntry.File = reader.ReadBytes(picUpload.ContentLength); } } user.Entries.Add(aEntry); db.Entries.Add(aEntry); db.SaveChanges(); if (model.SelectedTagIds != null) { foreach (var item in model.SelectedTagIds) { var selectedTag = new EntryTagEntries(); selectedTag.EntryId = db.Entries.Max(x => x.Id); selectedTag.TagId = db.EntryTags.Where(x => x.TagName == item).SingleOrDefault().Id.ToString(); db.EntryTagEntries.Add(selectedTag); } } db.SaveChanges(); var emails = db.Users.Where(x => x.GetMail).Select(x => x.Email).ToList(); var subject = user.Email + " har skrivit ett formellt inlägg."; var message = user.Email + " har lagt upp ett inlägg med titeln: " + model.Entries.Heading + "."; DataLogic.DbMethods.Methods.SendEmailInvitation(emails, message, subject); DataLogic.DbMethods.EmailJob.count += 1; return(RedirectToAction("IndexFormal", new { Id = user.Id })); } var tags = new List <SelectListItem>(); tags = db.EntryTags.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.TagName }).ToList(); model.TagNameList = tags; return(View(model)); }
// GET: Entries/Create public ActionResult CreateTest() { var model = new CreateEntryViewModel(); var tags = new List <SelectListItem>(); tags = db.EntryTags.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.TagName }).ToList(); model.TagNameList = tags; return(View(model)); }
public IActionResult CreateEntry(CreateEntryViewModel viewModel) { if (ModelState.IsValid) { _entryRepo.SaveEntry(viewModel); return(Redirect(nameof(Index))); // chèn xong thì chuyển hướng lại trang Index } // khi còn nhập thiếu input viewModel.Drivers = _driverRepo.GetAllDrivers(); viewModel.Shippers = _shipperRepo.GetAllShippers(); viewModel.Customers = _customerRepo.GetAllCustomer(); viewModel.Consignees = _consigneeRepo.GetAllConsignee(); return(View(viewModel)); }
// GET: Entries/Create public async Task <IActionResult> Create() { var vm = new CreateEntryViewModel(); var themes = await _context.Theme.ToListAsync(); var checkBoxListItems = new List <CheckBoxListItem>(); foreach (var theme in themes) { checkBoxListItems.Add(new CheckBoxListItem() { Id = theme.Id, Display = theme.Name, IsChecked = false }); } vm.Themes = checkBoxListItems; return(View(vm)); }
public ActionResult CreateInformalEntry(CreateEntryViewModel model, HttpPostedFileBase File, string Category) { var user = UserManager.FindById(User.Identity.GetUserId()); string fileString = null; if (File != null && File.ContentLength > 0) { fileString = FileUpload(File); if (fileString == null) { var CategoryList = Ctx.Categories.Where(c => c.CategoryType == "Formal").ToList(); List <string> CategoryListName = new List <string>(); foreach (var c in CategoryList) { CategoryListName.Add(c.CategoryName); } return(View(new CreateEntryViewModel { Title = model.Title, Content = model.Content, ErrorMessage = "Endast bildfiler tillåtna.", CategoryList = CategoryListName })); } } Ctx.InformalBlogEntries.Add(new InformalBlogModel { AttachedFile = fileString, Category = Category, BlogEntryTime = DateTime.Now, Title = model.Title, Content = model.Content, CreatorId = user.Id } ); Ctx.SaveChanges(); //string subject = "Nytt inlägg från " + user.FirstName + "."; //string emailText = "Inlägg med rubrik: " + model.Title + " finns nu att läsa."; //var emailHelper = new EmailHelper("*****@*****.**", "Kakan1210"); //emailHelper.SendEmailFormalBlog(subject, emailText, user.Id); return(RedirectToAction("Index", "InformalBlog")); }
public ActionResult CreateEntry(CreateEntryViewModel model, HttpPostedFileBase File, string Category) { var user = UserManager.FindById(User.Identity.GetUserId()); var fileString = FileUpload(File); Ctx.FormalBlogEntries.Add(new FormalBlogEntry { AttachedFile = fileString, Category = Category, BlogEntryTime = DateTime.Now, Title = model.Title, Content = model.Content, CreatorId = user.Id } ); Ctx.SaveChanges(); string subject = "Nytt inlägg från " + user.FirstName + "."; string emailText = "Inlägg med rubrik: " + model.Title + " finns nu att läsa."; var emailHelper = new EmailHelper("*****@*****.**", "Kakan1210"); emailHelper.SendEmailFormalBlog(subject, emailText, user.Id, Category, "Formal"); return(RedirectToAction("Index", "FormalBlog")); }
public async Task <IActionResult> Create(CreateEntryViewModel model) { if (!ModelState.IsValid) { return(Json(new { ok = false, msg = "Invalid form values" })); } var ids = Array.Empty <int>(); var amount = Math.Abs(model.Amount.Value); var monthlyBudgetID = GetLatestMonthlyBudget(model.AccountID); if (!Enum.TryParse <EntryType>(model.Type, out var entryType)) { entryType = EntryType.Transfer; } if (entryType == EntryType.Transfer) { if (!int.TryParse(model.Type.Split('-')[1], out var destinationAccountID)) { return(Json(new { ok = false, msg = "Invalid destination account ID" })); } var parameters = new { ids = new[] { model.AccountID, destinationAccountID } }; var accounts = Db.Query(conn => conn.Query <Account>("SELECT * FROM Accounts WHERE ID IN @ids", parameters)); var sourceAccountName = accounts.Single(a => a.ID == model.AccountID).Name; var destinationAccountName = accounts.Single(a => a.ID == destinationAccountID).Name; var destinationMonthlyBudgetID = GetLatestMonthlyBudget(destinationAccountID); var guid = Guid.NewGuid(); // For transfers, we set up separate entries for source and destination accounts // Note that we ignore the credit/debit selection here (a transfer is always a debit) Db.InsertOrUpdate(new Entry( accountID: model.AccountID, monthlyBudgetID: monthlyBudgetID, categoryID: model.CategoryID, date: model.Date, amount: -amount, note: $"Transfer to {destinationAccountName}", transferGuid: guid )); Db.InsertOrUpdate(new Entry( accountID: destinationAccountID, monthlyBudgetID: destinationMonthlyBudgetID, date: model.Date, amount: amount, note: $"Transfer from {sourceAccountName}", transferGuid: guid )); ids = new[] { model.AccountID, destinationAccountID }; } else { if (entryType == EntryType.Debit) { amount = -amount; } Db.InsertOrUpdate(new Entry( accountID: model.AccountID, monthlyBudgetID: monthlyBudgetID, categoryID: model.CategoryID, partyID: model.PartyID, date: model.Date, amount: amount, note: model.Note )); ids = new[] { model.AccountID }; } UnitOfWork.CommitChanges(); var getHtmlForUpdatedAccounts = ids.Select(async(id, i) => { var html = await RenderAccountHtml(id, i == 0 && !model.CategoryID.HasValue ? 0 : model.CategoryID); return(new { id, html }); }); var updatedData = await Task.WhenAll(getHtmlForUpdatedAccounts); return(Json(new { ok = true, updated = updatedData })); }
public async Task <IActionResult> Create([Bind("Id,UserId,Title,Description,Date")] Entry entry, CreateEntryViewModel model) { var user = await GetCurrentUserAsync(); if (ModelState.IsValid) { var selected = model.Themes.Where(x => x.IsChecked).Select(x => x.Id).ToList(); entry.ThemeEntries = new List <ThemeEntry>(); foreach (var s in selected) { ThemeEntry te = new ThemeEntry() { EntryId = entry.Id, ThemeId = s }; entry.ThemeEntries.Add(te); } entry.Date = DateTime.Today; entry.UserId = user.Id; _context.Add(entry); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(entry)); }