public IActionResult CompareMessage(Message message) { db.Messages.Add(message); db.SaveChanges(); ViewBag.String = "Сообщение отправлено."; return(View()); }
public void CreateOrder(Order order) { order.OrderTime = DateTime.Now; _appDbContent.Orders.Add(order); _appDbContent.SaveChanges(); var items = _shopCart.ListShopItems; foreach (var el in items) { var orderDetail = new OrderDetail() { SneakerId = el.Sneaker.Id, OrderId = order.Id, Price = el.Sneaker.Price, Adress = order.Adress, Name = order.Name, Phone = order.Phone, SneakerName = el.Sneaker.Name, Surname = order.Surname, SneakerSize = order.SneakerSizeOrder }; _appDbContent.OrderDetail.Add(orderDetail); } _appDbContent.SaveChanges(); }
public ActionResult Create(Contract contract) { if (HttpContext.Session.GetString("actions") == "admin") { try { using (appDBContent) { appDBContent.Contract.Add(contract); appDBContent.SaveChanges(); } return(RedirectToAction("Index")); } catch { ViewBag.Message = "Данные некорректны!"; return(View()); //return RedirectToAction("Index"); } } else { return(RedirectToRoute(new { controller = "Employee", action = "Login" })); } }
public ActionResult Create(DepositType depositType) { if (HttpContext.Session.GetString("actions") == "admin") { try { using (appDBContent) { if (depositType.capitalization > 0 && depositType.minMoney > 0 && depositType.percent > 0 && depositType.percent < 100 && depositType.period > 0 && depositType.maxMoney > depositType.minMoney) { appDBContent.DepositType.Add(depositType); appDBContent.SaveChanges(); } else { ViewBag.Message = "Данные некорректны!"; return(View()); } } return(RedirectToAction("Index")); } catch { return(View()); //return RedirectToAction("Index"); } } else { return(RedirectToRoute(new { controller = "Employee", action = "Login" })); } }
public void createOrder(Order order) { order.orderTime = DateTime.Now; appDBContent.Order.Add(new Order { orderName = order.orderName, orderAddress = order.orderAddress, orderPhone = order.orderPhone, email = order.email, orderTime = order.orderTime }); appDBContent.SaveChanges(); var items = shopCart.listShopItems; List <Order> currOrder = appDBContent.Order.Where(t => t.orderTime == order.orderTime).OrderBy(t => t.orderId).ToList(); foreach (var el in items) { appDBContent.OrderDetail.Add(new OrderDetail { orderId = currOrder[0].orderId, carId = el.car.carId, price = el.car.carPrice }); } appDBContent.SaveChanges(); }
public dynamic GetCart(IServiceProvider services) { ISession session = services.GetRequiredService <IHttpContextAccessor>()?.HttpContext.Session; string _cartId = session.GetString("cartId") ?? Guid.NewGuid().ToString(); session.SetString("cartId", _cartId); Cart cart = new Cart(_cartId); if (String.IsNullOrEmpty(session.GetString("profileId"))) { appDBContent.Carts.Add(cart); } else { cart.ProfileId = session.GetString("profileId"); appDBContent.Carts.Add(cart); } try { appDBContent.SaveChanges(); } catch (Exception e) { return(null); } return(cart); }
public ActionResult Create(Client client) { if (HttpContext.Session.GetString("actions") == "admin") { try { using (appDBContent) { List <Client> cl = new List <Client>(); cl = appDBContent.Client.Where(x => x.passport == client.passport).ToList(); if (cl.Count == 0) { appDBContent.Client.Add(client); appDBContent.SaveChanges(); } else { ViewBag.Message = "Клиент уже зарегистрирован в системе!"; return(View()); } } return(RedirectToAction("Index")); } catch { return(View()); //return RedirectToAction("Index"); } } else { return(RedirectToRoute(new { controller = "Employee", action = "Login" })); } }
public ActionResult Create(Employee emp) { if (HttpContext.Session.GetString("actions") == "admin") { try { using (appDBContent) { List <Employee> empl = new List <Employee>(); empl = appDBContent.Employee.Where(x => x.EmployeeLogin == emp.EmployeeLogin).ToList(); if (empl.Count == 0) { appDBContent.Employee.Add(emp); appDBContent.SaveChanges(); } else { ViewBag.Message = "Сотрудник уже зарегистрирован в системе!"; return(View()); } } return(RedirectToAction("Index")); } catch { return(View()); //return RedirectToAction("Index"); } } else { return(RedirectToAction("Login")); } }
public void AddToRoster(Unit unit) { this.appDBContent.RosterItem.Add(new RosterItem { rosterId = rosterId, unit = unit }); appDBContent.SaveChanges(); }
public void Remove(Service Service) { var item = _AppDBContent.Service.Where(x => x.ServiceId == Service.ServiceId).FirstOrDefault(); _AppDBContent.Service.Remove(item); _AppDBContent.SaveChanges(); }
public void CreateSubscription(Subscription Subscription) { Subscription.StartSubscription = DateTime.Now.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute).AddSeconds(DateTime.Now.Second); appDbContent.Subscription.Add(Subscription); appDbContent.SaveChanges(); }
public IActionResult Execution(int Id) { var order = _appDBContent.Orders .FirstOrDefault(o => o.Id == Id); order.Status = "На исполнении"; _appDBContent.SaveChanges(); return(RedirectToAction("Index")); }
public void AddToCart(Shoes shoes) { appDBContent.ShopCartItem.Add(new ShopCartItem { ShopCartId = ShopCartId, shoes = shoes, price = shoes.price }); appDBContent.SaveChanges(); }
public void AddAuthor(string nameAuthor) { appDBContent.Authors.Add(new Author { NameAuthor = nameAuthor, NormalizedNameAuthor = nameAuthor.ToUpper() }); appDBContent.SaveChanges(); }
//добавление в корзину позиции //кол-во = 1 пока при первом добавлении оставил public void AddToCart(Item item) { _appDBContent.shopCartItem.Add(new ShopCartItem { shopCartID = shopCartID, item = item, quantity = 1, price = item.price }); _appDBContent.SaveChanges(); }
public void AddToBasket(Book book) { _appDbContent.ShopBasketItem.Add(new ShopBasketItem { ShopBasketId = ShopBasketId, Book = book, Price = book.Price }); _appDbContent.SaveChanges(); }
public Auto GetAuto(int autoId) => appDBContent.Auto.FirstOrDefault(p => p.Id == autoId); //Search by ID public string AddAuto(Auto element) //Add object to DB { if (Autos.Select(s => s.Number == element.Number).Select(c => c == true).Contains(true)) //Validate if the object has already been added { return("Объект уже существует"); } appDBContent.Add(element); appDBContent.SaveChanges(); return("Автомобиль добавлен"); }
public bool Insert(Category category) { // проверка имени чтобы не совпадало if (_appDBContent.category.FirstOrDefault(c => string.Equals(c.name, category.name, StringComparison.OrdinalIgnoreCase)) != null) { return(false); } _appDBContent.category.Add(category); _appDBContent.SaveChanges(); return(true); }
public void AddToCart(Toy toy) { AppDBContent.ToyShopCartItem.Add(new ToyShopCartItem { ToyShopCartId = ToyShopCartId, toy = toy, price = toy.Price }); AppDBContent.SaveChanges(); }
public void AddToCart(Car car) { appDBContent.ShopCartItem.Add(new ShopCartItem { ShopCartId = ShopCartId, car = car, price = car.price }); appDBContent.SaveChanges(); }
public void AddToCart(GardeningItem item) { appDBContent.ShopCartItem.Add(new ShopCartItem { ShopCartId = ShopCartId, Item = item, Price = item.Price }); appDBContent.SaveChanges(); }
public void AddToCart(Course course) { appDBContent.ShopCourseItems.Add(new ShopCartItem { ShopCartId = this.ShopCartId, Course = course, Price = course.Price }); appDBContent.SaveChanges(); }
public void AddToSite(Site site) { appDBContent.ShopSitesItem.Add(new ShopSitesItem { ShopSitesId = ShopSiteId, site = site, price = site.price }); appDBContent.SaveChanges(); }
public bool Insert(Item item) { // проверка не повторения имени if (_appDBContent.item.FirstOrDefault(i => string.Equals(i.name, item.name, StringComparison.OrdinalIgnoreCase)) != null) { return(false); } _appDBContent.item.Add(item); _appDBContent.SaveChanges(); return(true); }
public void AddMatch(MatchAdd matchToAdd, Match newMatch, MatchParticipant MP1, MatchParticipant MP2) { appDBContent.Matches.Add(newMatch); appDBContent.SaveChanges(); appDBContent.MatchParticipant.Add(new MatchParticipant { player = Convert.ToString(matchToAdd.win), matchID = Convert.ToInt32(newMatch.Id), result = 1 }); appDBContent.MatchParticipant.Add(new MatchParticipant { player = Convert.ToString(matchToAdd.lose), matchID = Convert.ToInt32(newMatch.Id), result = 0 }); appDBContent.SaveChanges(); }
public ActionResult CreateProduct(Product product, int categoryId, IFormFile uploadedFile) { string path = $"/img/{DateTime.Now.ToString("yyyyMMddHHmmss")}.jpg"; using (var fileStream = new FileStream(_environment.WebRootPath + path, FileMode.CreateNew)) { uploadedFile.CopyTo(fileStream); } product.Category = _categories.AllCategories.Where(x => x.Id == categoryId).FirstOrDefault(); product.ImagePath = $"{path}"; _content.Product.Add(product); _content.SaveChanges(); return(RedirectToAction("List")); }
public void AddBook(string id, Book book) { LibraryToRead library = appDBContent.Libraries.FirstOrDefault(l => l.Guid.Equals(id)); if (library == null) { library = new LibraryToRead() { Guid = id }; appDBContent.Libraries.Add(library); } library.AddBook(book); appDBContent.SaveChanges(); }
//сохранить новую либо обновить существующую запись в БД public Guid SaveArticle(RegisteViewModel entity) { if (entity.id == default) { context.Entry(entity).State = EntityState.Added; context.RegisteViewModel.Add(entity); } else { context.Entry(entity).State = EntityState.Modified; } context.SaveChanges(); return(entity.id); }
public void createOrder(Order order) { try { if (order != null) { order.OrderTime = DateTime.Now; AppDBContent.Order.Add(order); var items = ShopCart.ListShopItems; //получаем все товары foreach (var elem in items) { var orderDetail = new OrderDetail() { CarId = elem.Car.Id, OrderId = order.Id, Price = elem.Car.Price }; AppDBContent.OrderDetail.Add(orderDetail); } AppDBContent.SaveChanges(); } } catch (Exception e) { Console.WriteLine("Ошибка: " + e); } }
public async Task <IActionResult> AddFile(IFormFile uploadedFile) { var currentUserid = _iuser.AllUsers.First(i => i.Email == User.Identity.Name); if (uploadedFile != null) { string path = _appEnvironment.WebRootPath + $"/Files/{currentUserid.Email}/"; Directory.CreateDirectory(path); // The path to the folder Files path += uploadedFile.FileName; // I save the file to a folder Files in the catalog wwwroot using (var fileStream = new FileStream(path, FileMode.Create)) { await uploadedFile.CopyToAsync(fileStream); } Files file = new Files { Name = uploadedFile.FileName, Path = path, UserId = currentUserid.Id }; _appDBContent.Files.Add(file); _appDBContent.SaveChanges(); } return(RedirectToAction("Index")); }