public User GetProductBoughtUser() { const string dailyProductAdder = "Product Bought"; var accountOf = db.Users.FirstOrDefault(n => n.LogName == dailyProductAdder); if (accountOf == null) { accountOf = new User() { LogName = dailyProductAdder, Name = dailyProductAdder, IsBlocked = false, IsAccessToAdmin = false, IsEmployee = false, IsOwner = false, TimeZoneID = userInfo.GetUser() .TimeZoneID, Email = "none", IsValidEmail = false }; db.Users.Add(accountOf); db.SaveChanges(); } return(accountOf); }
// // GET: /Admin/Inventory/ public ActionResult Index() { List <Inventory> inventories = db.Inventories.Include(i => i.Category).Include(n => n.QuantityType) .ToList(); IQueryable <Category> categories = db.Categories.Where(n => !n.IsExpense); var qty = db.QuantityTypes.FirstOrDefault(); if (qty == null) { return(View("Error2", new Exception("No quantity type exist."))); } foreach (Category category in categories) { if (!inventories.Any(n => n.CategoryID == category.CategoryID)) { var inventory = new Inventory { CategoryID = category.CategoryID, Quantity = 0, LastEditedby = userinfo.GetUserID(), QtyType = qty.QuantityTypeID }; db.Inventories.Add(inventory); inventories.Add(inventory); } } db.SaveChanges(); return(View(inventories)); }
public ActionResult Create(QuantityType quantitytype) { if (ModelState.IsValid) { db.QuantityTypes.Add(quantitytype); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(quantitytype)); }
public ActionResult Create(Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } GetDropDowns(category); return(View(category)); }
public ActionResult Create(QuantityConversation quantityconversation) { if (ModelState.IsValid) { db.QuantityConversations.Add(quantityconversation); db.SaveChanges(); return(RedirectToAction("Index")); } GetDropDowns(quantityconversation); return(View(quantityconversation)); }
public ActionResult Create(Code code) { try { code.GuidCode = Guid.NewGuid(); if (ModelState.IsValid) { db.Codes.Add(code); db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(User user) { User prevUser = db.Users.Find(user.UserID); if (ModelState.IsValid) { var roleManage = new RoleManage(); try { //admin roleManage.VerifyAddRemoveRole(user.LogName, RoleNames.Admin, prevUser.IsAccessToAdmin, user.IsAccessToAdmin); //sales roleManage.VerifyAddRemoveRole(user.LogName, RoleNames.Admin, prevUser.IsEmployee, user.IsEmployee); } catch (Exception ex) { } db.Entry(prevUser) .State = EntityState.Detached; db.Entry(user) .State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public void CreateExpense(AccountBalance accountbalance) { accountbalance.Dated = DateTime.Now; accountbalance.AddBy = _Userinfo.GetUserID(); accountbalance.IsAddedMoney = false; accountbalance.IsExpense = true; accountbalance.IsBoughtProduct = false; if (accountbalance.Amount < 0) { ModelState.AddModelError("Amount", "Amount can't be negative."); } double?sum = db.ViewSummaryAccountBalances.Sum(n => n.Balance); if (sum == null) { sum = 0; } var sum2 = (double)sum; if (sum2 < accountbalance.Amount) { ModelState.AddModelError("Amount", "Sorry your amount excceds your account balance " + sum2 + "."); } accountbalance.Amount = accountbalance.Amount * -1; if (ModelState.IsValid) { db.AccountBalances.Add(accountbalance); db.SaveChanges(); } }
public ActionResult Add(AccountBalance accountbalance) { if (User.Identity.IsAuthenticated) { double?sum = db.ViewSummaryAccountBalances.Sum(n => n.Balance); if (sum == null) { sum = 0; } var sum2 = (double)sum; if (sum2 < accountbalance.Amount) { ModelState.AddModelError("Amount", "Sorry your amount exceeds your account balance " + sum2 + "."); } var inventoryExtension = new InventoryExtension(); if (ModelState.IsValid && inventoryExtension.InventoryAdd(db, accountbalance)) { db.SaveChanges(); return(RedirectToAction("List", "AccountBalance")); } } GetDropDowns(); return(View(accountbalance)); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && User.Identity.IsAuthenticated) { //save last login var userinfo = new UserInfo(); User user = userinfo.GetUserSession(); user.LastLogIn = DateTime.UtcNow; using (var db = new JustFoodDBEntities()) { db.Entry(user).State = EntityState.Detached; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return(View(model)); }
public JsonResult Add(InventoryOutConfigViewDisplay inventory) { var result = new CustomJsonResult { Status = true, Message = "Successful", ConfigId = -1 }; if (inventory != null) { var quantityTypeExt = new QuantityTypeExtension(); decimal multiplier = 0; /* * * Passing DiscardCategoryID because Category id is for that inventory item category * which is irrelevent here. We are deduction small products by DiscardCategoryID * and so we are passing DiscardCategoryID instead of CategoryID * */ if (!quantityTypeExt.Mismatch(inventory.DiscardCategoryID, inventory.QuantityTypeID, out multiplier, false)) { var inventoryOutConfig = new InventoryOutConfig() { CategoryID = inventory.CategoryID, //category of that inventory DiscardItemCategory = inventory.DiscardCategoryID, //discarding category when item is sold. For say burguer category needs to deduct from breads. QtyType = inventory.QuantityTypeID, PerSaleQuantity = inventory.Quantity //keep the same quantity and id deduct by mathematics multiplication in the real time selling not here. }; db.InventoryOutConfigs.Add(inventoryOutConfig); db.SaveChanges(); //updating configid. result.ConfigId = inventoryOutConfig.InventoryOutConfigID; return(Json(result)); } } result.Status = false; result.Message = "Either quantity type validation failed or server internal error. Try again with different quantity type."; return(Json(result)); }
public ActionResult Create(AccountBalance accountbalance) { if (User.Identity.IsAuthenticated) { accountbalance.Dated = DateTime.UtcNow; accountbalance.AddBy = _Userinfo.GetUserSession() .UserID; accountbalance.IsBoughtProduct = false; accountbalance.IsAddedMoney = true; accountbalance.IsExpense = false; if (accountbalance.Amount < 0) { ModelState.AddModelError("Amount", "Amount can't be negative."); } if (ModelState.IsValid) { _Db.AccountBalances.Add(accountbalance); _Db.SaveChanges(); return(RedirectToAction("Index")); } } GetUsers(); return(View(accountbalance)); }
public ActionResult Pay(SalaryPaid salarypaid) { var userinfo = new UserInfo(); User user = userinfo.GetUser(salarypaid.UserID); if (user != null) { salarypaid.PaidDate = DateTime.UtcNow; salarypaid.Salary = user.Salary; if (ModelState.IsValid) { db.SalaryPaids.Add(salarypaid); // add expense Category categorySalary = db.Categories.FirstOrDefault(n => n.Category1 == "Salary"); if (categorySalary != null) { var expenseController = new ExpenseController(); var accountBalance = new AccountBalance { AccountOf = salarypaid.UserID, Amount = salarypaid.Paid, CategoryProduct = categorySalary.CategoryID }; expenseController.CreateExpense(accountBalance); db.SaveChanges(); } else { goto Error; } return(RedirectToAction("Index")); } } Error: ViewBag.UserID = new SelectList(db.Users, "UserID", "LogName", salarypaid.UserID); return(View(salarypaid)); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { //check the code var db = new JustFoodDBEntities(); Code code = db.Codes.FirstOrDefault(m => m.Code1 == model.Code); if (code == null) { ModelState.AddModelError(model.Code, "Your given code is not valid."); return(View(model)); } // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); //create new user. if (code.Percentage == null) { code.Percentage = 0; } if (code.Salary == null) { code.Salary = 0; } var user = new User { LogName = model.UserName, Name = model.PersonName, IsEmployee = code.IsEmployee, IsOwner = code.IsOwner, IsAccessToAdmin = code.IsAccessToAdmin, Percentage = (double)code.Percentage, Salary = (double)code.Salary, Email = model.Email, IsValidEmail = true }; //there is no need to keep the used code. db.Entry(code).State = EntityState.Deleted; db.Users.Add(user); db.SaveChanges(); //Roles.CreateRole(""); var roleManager = new RoleManage(); string role = ""; if (user.IsAccessToAdmin) { role = RoleNames.Admin; } else if (user.IsEmployee) { role = RoleNames.SalesMan; } roleManager.AddRole(user.LogName, role); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View(model)); }