public IActionResult Register([FromBody] User user) { if (user.Email != null && user.PasswordHash != null && user.PasswordHash.Length >= 6) { var isUniqueEmail = db.Users.FirstOrDefault(x => x.Email == user.Email); if (isUniqueEmail == null) { if (user.Email != null) { try { db.Users.Add(new User() { Email = user.Email, PasswordHash = user.PasswordHash, Role = UserRole.User.ToString() }); db.SaveChanges(); return(StatusCode(200, "New user successfully added")); //return Ok(); } catch { return(StatusCode(500)); } } } return(StatusCode(400)); } return(StatusCode(400)); }
public IActionResult AddToWish([FromBody] int id) { var username = User.Identity.Name; try { if (db.Wishlist.FirstOrDefault(x => x.ProductId == id && x.UserId == db.Users.First(z => z.Email == username).Id) == null) { if (db.Products.FirstOrDefault(x => x.Id == id) != null) { db.Wishlist.Add(new Wishlist() { UserId = db.Users.First(x => x.Email == username).Id, ProductId = id }); db.SaveChanges(); return(StatusCode(200)); } return(StatusCode(400, $"Product with id = {id} not found")); } return(StatusCode(403, "Product already in wishlist")); } catch { return(StatusCode(500, "Internal server error")); } }
public ActionResult Create([Bind(Exclude = "Technology")] TechnologyContent technologyContent) { try { if (ModelState.IsValid) { technologyContent.Description = HttpContext.Server.HtmlEncode(technologyContent.Description); technologyContent.Example = HttpContext.Server.HtmlEncode(technologyContent.Example); technologyContent.IsActive = true; technologyContent.TechnologyContentGuid = Guid.NewGuid(); technologyContent.SeqNo = db.TechnologyContent.Count(x => x.TechnologyGuid == technologyContent.TechnologyGuid) + 1; db.TechnologyContent.Add(technologyContent); db.SaveChanges(); return(RedirectToAction("Details", "Technology", new { id = technologyContent.TechnologyContentGuid })); } ViewBag.TechnologyGuid = new SelectList(db.Technologies.AsNoTracking(), "TechnologyGuid", "TechnologyName", technologyContent.TechnologyGuid); return(View(technologyContent)); } catch (Exception ex) { log.Error("TechnologyContentController Create- post Action : " + ex.Message); return(RedirectToAction("Index", "Error", new { exception = ex })); } }
public IActionResult AddToCart([FromBody] int id) { var username = User.Identity.Name; //if not auth or token expired =null if (username != null) { try { var user = db.Users.First(x => x.Email == username); var product = db.Products.First(x => x.Id == id); var exist = db.Cart.FirstOrDefault(x => x.UserId == user.Id && x.ProductId == product.Id); if (exist == null) { db.Cart.Add(new Cart { UserId = user.Id, ProductId = product.Id, Quantity = 1 }); db.SaveChanges(); return(StatusCode(200)); } return(StatusCode(403, "Product already exist")); } catch { return(StatusCode(500, "Internal server error")); } } return(StatusCode(200, "Not authorized. Cart only local")); }
public IActionResult CreateProduct(Product product) { db.Products.Add(product); db.SaveChanges(); int id = product.Id; return(Json(id)); }
public ActionResult Create(Aluno aluno) { aluno.DtCadastro = DateTime.Now; aluno.Status = "A"; if (ModelState.IsValid) { db.Alunos.Add(aluno); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(Voluntario aula) { aula.DtCadastro = DateTime.Now; aula.Status = "A"; if (ModelState.IsValid) { db.Voluntarios.Add(aula); db.SaveChanges(); } return(View("Index", db.Voluntarios.ToList())); }
public ActionResult Create(Professor professor) { professor.DtCadastro = DateTime.Now; professor.Status = "A"; if (ModelState.IsValid) { db.Professores.Add(professor); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(Doacao doacao) { doacao.DtCadastro = DateTime.Now; doacao.Status = "A"; //var preco = float.Parse(doa) if (ModelState.IsValid) { db.Doacoes.Add(doacao); db.SaveChanges(); } return(RedirectToAction("Inventario")); }
public ActionResult Create(Ementa ementa) { ementa.DtCadastro = DateTime.Now; ementa.Status = "A"; if (ModelState.IsValid) { db.Ementas.Add(ementa); db.SaveChanges(); } return(RedirectToAction("Index")); }
public virtual int Add(T entity) { if (GetAll().Any()) { entity.Id = GetAll().Max(u => u.Id) + 1; } else { entity.Id = 1; } _context.Set <T>().Add(entity); _context.SaveChanges(); return(entity.Id); }
public void RemoveCategory(CategoryModel category) { using (Context.AppContext dbContext = new Context.AppContext()) { dbContext.Categories.Remove(category); dbContext.SaveChanges(); } }
public void RemoveBalance(BalanceModel balance) { using (Context.AppContext dbContext = new Context.AppContext()) { dbContext.Balance.Remove(balance); dbContext.SaveChanges(); } }
public void RemoveCost(CostModel cost) { using (Context.AppContext dbContext = new Context.AppContext()) { dbContext.Costs.Remove(cost); dbContext.SaveChanges(); } }
internal void UpdateCategory(CategoryModel updateCategory) { using (Context.AppContext dbContext = new Context.AppContext()) { CategoryModel currentCategory = dbContext.Categories.FirstOrDefault(c => c.Id == updateCategory.Id); dbContext.Entry(currentCategory).CurrentValues.SetValues(updateCategory); dbContext.SaveChanges(); } }
internal void UpdateBalance(BalanceModel updateBalance) { using (Context.AppContext dbContext = new Context.AppContext()) { BalanceModel currentBalance = dbContext.Balance.FirstOrDefault(b => b.Id == updateBalance.Id); dbContext.Entry(currentBalance).CurrentValues.SetValues(updateBalance); dbContext.SaveChanges(); } }
internal void UpdateCost(CostModel updateCost) { using (Context.AppContext dbContext = new Context.AppContext()) { CostModel currentCost = dbContext.Costs.FirstOrDefault(c => c.Id == updateCost.Id); dbContext.Entry(currentCost).CurrentValues.SetValues(updateCost); dbContext.SaveChanges(); } }
public ActionResult Create(Investment investment) { if (ModelState.IsValid) { db.Investments.Add(investment); db.SaveChanges(); return(RedirectToAction("Index")); } var category = ConfigurationManager.AppSettings["InvestmentCategory"]; var list = category.Split(',').Select(x => new { item = x, value = x }); ViewBag.InvestmentTypes = new SelectList(list, "value", "item"); ViewBag.TransactionType = new SelectList(new List <object>() { new { item = "Credit", value = 1 }, new { item = "Debit", value = 2 } }, "value", "item"); return(View(investment)); }
public ActionResult Create(Withdrawal withdraw) { try { if (ModelState.IsValid) { Transaction transaction = new Transaction(); transaction.TranscationGuid = Guid.NewGuid(); var transFor = db.TransactionFor.FirstOrDefault(x => x.TranscationForGuid == withdraw.TranscationForGuid).TranscationFor; if (transFor == "Return Money(Self)" || transFor == "Return Money(Third Party)") { transaction.TranscationType = Enum.Enums.TransactionType.Credit; } else { transaction.TranscationType = Enum.Enums.TransactionType.Debit; } transaction.TranscationForGuid = withdraw.TranscationForGuid; transaction.PersonGuid = withdraw.PersonGuid; transaction.Amount = withdraw.Amount; transaction.Interest = withdraw.Interest; transaction.IsApproved = null ; transaction.TransactionDate = withdraw.TransactionDate; db.Transactions.Add(transaction); db.SaveChanges(); return(RedirectToAction("Index", "Transactions")); } ViewBag.PersonGuid = new SelectList(db.Persons, "PersonGuid", "LoginId", withdraw.PersonGuid); ViewBag.TransactionFor = new SelectList(db.TransactionFor.Where(x => x.TransactionType == 2), "TranscationForGuid", "TranscationFor"); return(View(withdraw)); } catch (Exception ex) { log.Error("WithdrawalController Create - Post Action : " + ex.Message); return(RedirectToAction("Index", "Error", new { exception = ex })); } }
public ActionResult Post([FromBody] Contacto contacto) { var valida = context.contacto.FirstOrDefault(c => c.nombreCompleto == contacto.nombreCompleto); if (valida == null) { try { context.contacto.Add(contacto); context.SaveChanges(); return(Ok()); } catch (Exception ex) { return(BadRequest()); } } else { return(BadRequest("El registro ya existe")); } }
public ActionResult Create([Bind(Exclude = "TechnologyContents")] Technology technology) { try { if (ModelState.IsValid) { technology.TechnologyGuid = Guid.NewGuid(); db.Technologies.Add(technology); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(technology)); } catch (Exception ex) { log.Error("TechnologyController Create -Post Action : " + ex.Message); return(RedirectToAction("Index", "Error", new { exception = ex })); } }
public IEnumerable <Category> Post(Category category) { try { List <Category> categories = db.Categories.ToList(); if (category.ParentCategory == null || categories.Exists(x => x.Id == category.ParentCategory)) { db.Categories.Add(category); db.SaveChanges(); return(db.Categories.ToList()); } else { return(categories); } } catch { List <Category> categories = new List <Category>(); categories.Add(category); return(categories); } }
bool IFile.SaveChanges() { return(_context.SaveChanges() >= 0); }
public TEntity Add(TEntity obj) { obj = DbSet.Add(obj); _context.SaveChanges(); return(obj); }
public ActionResult Create(Deposit deposit) { log.Info(deposit.TranscationForGuid); log.Info(deposit.TransactionFor); if (ModelState.IsValid) { List <Transaction> transactions = new List <Transaction>(); if ((int)deposit.Amount > 0) { Transaction transaction = new Transaction() { TranscationGuid = Guid.NewGuid(), Amount = deposit.Amount, TranscationForGuid = deposit.TranscationForGuid, TransactionDate = deposit.TransactionDate, TranscationType = Enum.Enums.TransactionType.Credit, PersonGuid = deposit.PersonGuid }; transactions.Add(transaction); } if ((int)deposit.SelfInterest > 0) { Transaction selfInterestTransaction = new Transaction() { TranscationGuid = Guid.NewGuid(), Amount = deposit.SelfInterest, TransactionFor = db.TransactionFor.FirstOrDefault(x => x.TranscationFor == "Interest(Self)"), TransactionDate = deposit.TransactionDate, TranscationType = Enum.Enums.TransactionType.Credit, PersonGuid = deposit.PersonGuid }; transactions.Add(selfInterestTransaction); } if ((int)deposit.ExternalInterest > 0) { Transaction externalInterestTransaction = new Transaction() { TranscationGuid = Guid.NewGuid(), Amount = deposit.ExternalInterest, TransactionFor = db.TransactionFor.FirstOrDefault(x => x.TranscationFor == "Interest(Third Party)"), TransactionDate = deposit.TransactionDate, TranscationType = Enum.Enums.TransactionType.Credit, PersonGuid = deposit.PersonGuid }; transactions.Add(externalInterestTransaction); } db.Transactions.AddRange(transactions); db.SaveChanges(); EmailService emailService = new EmailService(); //log.Error("Person:" + deposit.Person.) emailService.SendMail(db.Persons.FirstOrDefault(x => x.PersonGuid == deposit.PersonGuid), transactions); return(RedirectToAction("Index")); } ViewBag.PersonGuid = new SelectList(db.Persons, "PersonGuid", "LoginId", deposit.PersonGuid); ViewBag.TransactionFor = new SelectList(db.TransactionFor.Where(x => x.TransactionType == 1), "TranscationForGuid", "TranscationFor"); //ViewBag.TransactionType = new SelectList(new List<object>() { new { item = "Credit", value = "1" }, new { item = "Debit", value = "2" } }, "value", "item"); return(View(deposit)); }
public IActionResult DoOrder([FromBody] UserData userData) { var username = User.Identity.Name; try { var user = db.Users.First(x => x.Email == username); var userCart = db.Cart.Where(x => x.UserId == user.Id).ToList(); if (userCart.Count > 0) { int orderId = userCart[0].Id; foreach (var product in userCart) { var order = new ActiveOrder() { UserId = user.Id, OrderId = orderId, IsComplete = false, OrderDateTime = DateTime.Now, ProductId = product.ProductId, Quantity = product.Quantity, Cost = db.Products.First(x => x.Id == product.ProductId).Cost }; db.ActiveOrders.Add(order); db.Cart.Remove(product); db.SaveChanges(); } var databaseUserData = db.UsersData.FirstOrDefault(x => x.UserId == user.Id); if (databaseUserData != null) { databaseUserData.Address = userData.Address; databaseUserData.City = userData.City; databaseUserData.Country = userData.Country; databaseUserData.FirstName = userData.FirstName; databaseUserData.LastName = userData.LastName; databaseUserData.MobileNumber = userData.MobileNumber; databaseUserData.Zipcode = userData.Zipcode; db.UsersData.Update(databaseUserData); db.SaveChanges(); } else { userData = new UserData() { UserId = user.Id, Address = userData.Address, City = userData.City, Country = userData.Country, FirstName = userData.FirstName, LastName = userData.LastName, MobileNumber = userData.MobileNumber, Zipcode = userData.Zipcode }; db.UsersData.Add(userData); db.SaveChanges(); } return(StatusCode(200)); } return(StatusCode(400, "Cart on server is empty")); } catch (Exception ex) { return(StatusCode(500, "Internal server error" + ex)); } }