示例#1
0
        public ActionResult CreateBook([Bind(Include = "BookId,Title,Publisher,Year,CoverPage,ISBN,Author,Category,Price", Exclude = "CoverPage")] Book book)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase poImgFile = Request.Files["CoverPage"];


                string path = @"\Images/" + poImgFile.FileName;
                poImgFile.SaveAs(Server.MapPath("~") + @"\" + path);
                book.CoverPage = path;

                //Check book if exist
                int count = (from x in db.Book
                             where x.Title == book.Title
                             where x.ISBN == book.ISBN
                             select x).Count();

                if (count == 0)
                {
                    db.Book.Add(book);
                    db.SaveChanges();
                    return(RedirectToAction("IndexBook"));
                }

                else
                {
                    ViewBag.errorMessage = "Book already exist. Please create new book";
                    return(View(book));
                }
            }

            return(View(book));
        }
示例#2
0
        public ActionResult Order([Bind(Include = "Id,info,Email,Name,Phone,Street,City,ProductId")] Purchase p)
        {
            Product product = db.Products.Find(p.ProductId);

            p.Product = product;
            UpdateModel(p);
            db.Purchases.Add(p);
            db.SaveChanges();
            return(Json("Sended"));
        }
示例#3
0
 public ActionResult Edit([Bind(Include = "Id,Email,ForName,SurName,Phone,Photo")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
示例#4
0
        public ActionResult Create([Bind(Include = "Id,CategoryName")] ProductsCategory productsCategory)
        {
            if (ModelState.IsValid)
            {
                ProductsCategory pc = db.ProductsCategory.Add(productsCategory);
                db.SaveChanges();
                return(Json(new { text = "Added", Id = pc.Id }));
            }

            return(Json("Error"));
        }
        public ActionResult Create([Bind(Include = "registeredUserId,fullName,userName,password,role,PhoneNo,Email,ShipAddress")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.RegisteredUser.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "Id,CategoryName")] ArticleCategory articleCategory)
        {
            if (ModelState.IsValid)
            {
                ArticleCategory ar = db.ArticleCategories.Add(articleCategory);
                db.SaveChanges();
                return(Json(new { text = "Added", Id = ar.Id }));
            }

            return(Json("Error"));
        }
示例#7
0
        public ActionResult Create([Bind(Include = "Id,Email,Date")] Newsletter_Subscribers newsletter_Subscribers)
        {
            if (ModelState.IsValid)
            {
                db.Newsletters_Subscribers.Add(newsletter_Subscribers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(newsletter_Subscribers));
        }
示例#8
0
        public ActionResult Create([Bind(Include = "Id,info,Email,Name,Street,ProductId,City")] Purchase purchase)
        {
            if (ModelState.IsValid)
            {
                db.Purchases.Add(purchase);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductId = new SelectList(db.Products, "Id", "Thumb", purchase.ProductId);
            return(View(purchase));
        }
示例#9
0
        public ActionResult SignUp([Bind(Include = "registeredUserId,fullName,userName,password,role,PhoneNo,Email,ShipAddress")] Customer customer)
        {
            //access to db. get username and password
            MyAppDbContext db = new MyAppDbContext();

            if (ModelState.IsValid)
            {
                int count = (from x in db.RegisteredUser
                             where x.userName == customer.userName
                             where x.password == customer.password
                             select x).Count();

                //check whether acc already exist
                if (count == 0)
                {
                    ViewBag.errMsg = "Registration Successful. Please Login";
                    db.Address.Add(customer.ShipAddress);
                    db.RegisteredUser.Add(customer);
                    db.SaveChanges();
                    return(RedirectToAction("Login", "AuthAuth"));
                }
                else
                {
                    //check whether acc already exist
                    ViewBag.errMsg = "This account already registered";
                    return(View(customer));
                }
            }
            else
            {
                return(View(customer));
            }
        }
 public static void Run(MyAppDbContext db)
 {
     db.Address.AddOrUpdate(s => s.Id,
                            new Address
     {
         Id       = 1,
         City     = "Edinburgh",
         Country  = "U.K.",
         Line1    = "Line1 x1",
         Line2    = "Line2 x1",
         Line3    = "Line3 x1",
         PostCode = "EH88JU",
         Version  = TimestampHelper.Generate()
     }
                            ,
                            new Address
     {
         Id       = 2,
         City     = "Aberdeen",
         Country  = "U.K.",
         Line1    = "Line1 x2",
         Line2    = "Line2 x2",
         Line3    = "Line3 x2",
         PostCode = "EH37JU",
         Version  = TimestampHelper.Generate()
     }
                            );
     db.SaveChanges();
 }
示例#11
0
        public ActionResult Create([Bind(Include = "Id,Title,Text")] Newsletter newsletter, bool sendNow)
        {
            if (ModelState.IsValid)
            {
                newsletter.Date = DateTime.Now;
                string tmp  = newsletter.Text;
                var    item = db.Newsletters.Add(newsletter);
                db.SaveChanges();
                if (sendNow == true)
                {
                    item.Send();
                }
                return(RedirectToAction("Index"));
            }

            return(View(newsletter));
        }
示例#12
0
        public IActionResult IntroducereInLaminare()
        {
            // Selectam din lista sql primul blum care nu e dat afara sau retur
            Blum blumModificat = _context.Blums.Where(b => !b.IsDatAfara && !b.IsRetur).FirstOrDefault();

            if (blumModificat != null)
            {
                // Ii atribuim proprietate IsDataAfara = true plus data si ora
                blumModificat.IsDatAfara      = true;
                blumModificat.DataOraLaminare = DateTime.Now.ToString("dd/MM/yyyy HH:mm");
                //Salvam modificari in sql
                _context.SaveChanges();
                // Incrementam counter bare data afara
                Auxiliar.CounterBareDateAfara++;
                // Scriere date blum in PLC
                Auxiliar.ScriereInPlc(blumModificat);
            }
            return(RedirectToAction("Index"));
        }
        public void TestMethod()
        {
            var models = r.AddItem(model1);

            _context.SaveChanges();
            var dbItem = FindEqualModel(r, model1);

            Assert.IsNotNull(dbItem);
            Assert.AreEqual(dbSet.Count(), r.AllItems.Count());
            r.DeleteItem(dbItem.Id);
            _context.SaveChanges();

            Assert.AreEqual(dbSet.Count(), r.AllItems.Count());
            Assert.IsNull(FindEqualModel(r, model1));
            r.AddItems(new T[] { model1, model2 });
            _context.SaveChanges();

            var dbItem1 = FindEqualModel(r, model1);

            Assert.IsNotNull(dbItem1);
            var dbItem2 = FindEqualModel(r, model2);

            Assert.IsNotNull(dbItem2);
            Assert.AreEqual(dbSet.Count(), r.AllItems.Count());

            r.DeleteItem(dbItem1.Id);
            _context.SaveChanges();
            dbItem1 = FindEqualModel(r, model1);
            Assert.IsNull(dbItem1);
            Assert.AreEqual(dbSet.Count(), r.AllItems.Count());

            ChangeModel(dbItem2);

            var dbItem2m = FindEqualModel(r, dbItem2);

            Assert.IsNotNull(dbItem2m);

            r.DeleteItem(dbItem2m.Id);
            dbItem2 = FindEqualModel(r, dbItem2m);
            Assert.IsNull(dbItem2);
            Assert.AreEqual(dbSet.Count(), r.AllItems.Count());
        }
示例#14
0
 public ActionResult Create([Bind(Include = "Id,Name,Description,WorkRange")] Portfolio portfolio)
 {
     try
     {
         HttpPostedFileBase uploadedFile = Request.Files["PhotoP"];
         if (uploadedFile.ContentLength > 0)
         {
             var Filename = System.Guid.NewGuid().ToString() + "." + uploadedFile.FileName.Split('.')[1].ToString();
             portfolio.Photo = Filename;
             uploadedFile.SaveAs(HttpContext.Server.MapPath("~/Images/Portfolio/") + Filename);
         }
         db.Portfolios.Add(portfolio);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception exc)
     {
         return(View(portfolio));
     }
 }
示例#15
0
        public JsonResult DeleteConfirmed(int id)
        {
            PageContact pageContact = db.PageContacts.Find(id);

            if (pageContact == null)
            {
                return(Json("Error"));
            }
            db.PageContacts.Remove(pageContact);
            db.SaveChanges();
            return(Json("Deleted"));
        }
示例#16
0
        public JsonResult AddFile()
        {
            string[]           images       = { "png", "jpg", "gif", "svg" };
            var                mess         = "";
            Files              f            = new Files();
            HttpPostedFileBase uploadedFile = Request.Files["File"];
            var                fileName1    = uploadedFile.FileName;

            if (uploadedFile.ContentLength > 0)
            {
                fileName1 = System.Guid.NewGuid().ToString() + "." + uploadedFile.FileName.Split('.')[1].ToString();
                f.Path    = "/Files/Chat/" + fileName1;
                f.Name    = uploadedFile.FileName;
                db.Files.Add(f);
                db.SaveChanges();
                uploadedFile.SaveAs(Server.MapPath("~/Files/Chat/" + fileName1));
            }
            else
            {
                return(Json("Error"));
            }
            if (images.Contains(uploadedFile.FileName.Split('.')[1].ToString()))
            {
                mess = "<a href=\"" + f.Path + "\"><div class=\"chat-message-image\" style=\"background-image:url('" + f.Path + "')\"></div></a>";
            }
            else
            {
                mess = "<a class='chat-message-file-" + uploadedFile.FileName.Split('.')[1].ToString() + "' href='" + f.Path + "'>" + f.Name + "</a>";
            }


            return(Json(mess));
        }
示例#17
0
        public bool SaveChanges()
        {
            try
            {
                _context.SaveChanges();
                return(true);
            }
#pragma warning disable 0168
            catch (Exception e)
#pragma warning restore 0168
            {
                return(false);
            }
        }
示例#18
0
        public bool SaveChanges()
        {
            try
            {
                _context.SaveChanges();
                return(true);
            }

            catch (Exception e)

            {
                return(false);
            }
        }
示例#19
0
        public void AddToCart(Drink drink, int amount)
        {
            var shoppingCartItem =
                _myAppDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Drink.DrinkId == drink.DrinkId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Drink          = drink,
                    Amount         = 1
                };

                _myAppDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }
            _myAppDbContext.SaveChanges();
        }
示例#20
0
        public ActionResult About()
        {
            int id = 1;
            CV  cV = db.CV.Find(id);

            if (cV == null)
            {
                cV = new CV()
                {
                    Id          = 1,
                    ForName     = "",
                    SurName     = "",
                    Photo       = "",
                    Description = "",
                    Jobs        = new List <CVJobs>(),
                    School      = new List <CVSchool>(),
                    Skill       = new List <CVSkills>()
                };
                db.CV.Add(cV);
                db.SaveChanges();
            }
            return(View(cV));
        }
示例#21
0
      public ActionResult Create([Bind(Include = "OrderId, PaymentType, TotalPrice,ShipFee, Date")] Order order)
      {
          if (ModelState.IsValid)
          {
              var      custid = Int32.Parse(Request.Cookies["UserId"].Value);
              Customer cust   = (from x in db.Customer
                                 where x.registeredUserId == custid
                                 select x).Single();
              order.Customer = cust;
              List <Cart> IsCart = (List <Cart>)Session["Cart"];


              order.OrderCustomerid = custid;
              order.Date            = DateTime.Now;
              db.Order.Add(order);
              db.SaveChanges();

              for (int i = 0; i < IsCart.Count; i++)
              {
                  var book = db.Book.Find(IsCart[i].Book.BookId);
                  if (book.BookId > 0)
                  {
                      IsCart[i].OrderID = order.OrderId;
                      IsCart[i].BookID  = book.BookId;

                      db.Carts.Add(IsCart[i]);

                      db.SaveChanges();
                  }
              }
              Session["Cart"] = null;
              return(RedirectToAction("OrderCustomer/" + Request.Cookies["UserId"].Value));
          }

          return(View(order));
      }
示例#22
0
        public ActionResult CreateAsset(Asset postData)
        {
            var assetEntity = new AssetEntity();

            assetEntity.Description = postData.Description;
            assetEntity.Name        = postData.Name;
            assetEntity.CreatedOn   = DateTime.UtcNow;

            _dbContext.Assets.Add(assetEntity);
            _dbContext.SaveChanges();

            // logic to insert this record in DB
            ViewData["Entity"] = "Asset";
            return(View("Success"));
        }
示例#23
0
        public IActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                MyAppUser user = new MyAppUser();
                user.UserName = model.UserName;
                user.Password = model.Password;
                user.Roles    = "Manager,Administrator";

                db.MyAppUsers.Add(user);
                db.SaveChanges();

                ViewData["message"] = "User created successfully!";
            }
            return(View());
        }
示例#24
0
        public Chat_Message addMessageToRoom(int room, string user, string message)
        {
            MyAppDbContext db        = new MyAppDbContext();
            var            room_chat = db.Chat_Room.Find(room);
            var            user_name = room_chat.Users.SingleOrDefault(s => s.User.Email == user);
            Chat_Message   m         = new Chat_Message()
            {
                Text = message,
                User = user_name,
                Date = DateTime.Now
            };

            room_chat.Messages.Add(m);
            room_chat.LastUpdate = DateTime.Now;
            user_name.LastView   = DateTime.Now;
            db.Chat_Message.Add(m);
            db.SaveChanges();
            return(m);
        }
示例#25
0
 public ActionResult Edit([Bind(Include = "Id,Name,Prine,Demo,Description")] Product product, string stringofphoto, int CatId = 0)
 {
     try
     {
         MyAppDbContext     ctxt         = new MyAppDbContext();
         Product            t            = ctxt.Products.Single(p => p.Id == product.Id);
         HttpPostedFileBase uploadedFile = Request.Files["Thumbs"];
         if (uploadedFile.ContentLength > 0)
         {
             if ((System.IO.File.Exists(HttpContext.Server.MapPath("~/Images/Product/") + t.Thumb)))
             {
                 System.IO.File.Delete(HttpContext.Server.MapPath("~/Images/Product/") + t.Thumb);
             }
             var Filename = System.Guid.NewGuid().ToString() + "." + uploadedFile.FileName.Split('.')[1].ToString();
             product.Thumb = Filename;
             uploadedFile.SaveAs(HttpContext.Server.MapPath("~/Images/Product/") + Filename);
         }
         if (stringofphoto != null)
         {
             var array = stringofphoto.Split('|');
             for (int i = 0; i < array.Length; i++)
             {
                 if (array[i] != "")
                 {
                     Photo p = new Photo()
                     {
                         Path = array[i]
                     };
                     t.Photos.Add(p);
                     db.SaveChanges();
                 }
             }
         }
         UpdateModel(t);
         ctxt.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception exc)
     {
         return(View(product));
     }
 }
 public static void Run(MyAppDbContext db)
 {
     db.ContactAddress.AddOrUpdate(s => s.Id,
                                   new ContactAddress
     {
         Id          = 1,
         AddressId   = 1,
         ContactId   = 2,
         AddressType = DataStructure.AddressTypeEnum.Type1
     },
                                   new ContactAddress
     {
         Id          = 2,
         AddressId   = 2,
         ContactId   = 2,
         AddressType = DataStructure.AddressTypeEnum.Type3
     }
                                   );
     db.SaveChanges();
 }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (MyAppDbContext db = new MyAppDbContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
示例#28
0
        public void CreateOrder(Order order)
        {
            order.OrderPlaced = DateTime.Now;

            _myAppDbContext.Orders.Add(order);

            var shoppingCartItems = _shoppingCart.ShoppingCartItems;

            foreach (var shoppingCartItem in shoppingCartItems)
            {
                var orderDetail = new OrderDetail()
                {
                    Amount  = shoppingCartItem.Amount,
                    DrinkId = shoppingCartItem.Drink.DrinkId,
                    OrderId = order.OrderId,
                    Price   = shoppingCartItem.Drink.Price
                };

                _myAppDbContext.OrderDetails.Add(orderDetail);
            }

            _myAppDbContext.SaveChanges();
        }
示例#29
0
        public MainWindow()
        {
            MyAppDbContext context = new MyAppDbContext(
                new DbContextOptionsBuilder <MyAppDbContext>()
                .UseSqlServer(new SqlConnectionStringBuilder
            {
                DataSource         = "127.0.0.1",
                InitialCatalog     = "Univercity",
                IntegratedSecurity = true
            }.ConnectionString)
                .Options);



            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            context.Faculties.Add(new Faculty {
                Name = "F2"
            });
            context.SaveChanges();

            InitializeComponent();
        }
示例#30
0
 public static void Run(MyAppDbContext db)
 {
     db.Contact.AddOrUpdate(s => s.Id,
                            new Contact
     {
         Id        = 1,
         Email     = "*****@*****.**",
         FirstName = "firstName1",
         LastName  = "lastName1",
         Title     = "title1",
         Version   = TimestampHelper.Generate()
     },
                            new Contact
     {
         Id        = 2,
         Email     = "*****@*****.**",
         FirstName = "firstName2",
         LastName  = "lastName2",
         Title     = "title2",
         Version   = TimestampHelper.Generate()
     }
                            );
     db.SaveChanges();
 }