예제 #1
0
        public void IncreaseView(long id)
        {
            var model = db.Products.Find(id);

            model.ViewCount += 1;
            db.SaveChanges();
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "ID,UserName,PassWord,Name,Address,Email,Phone,Image,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Status")] User user)
        {
            Boolean check = false;
            var     model = new UserDAO();

            foreach (var item in model.UsLogin())
            {
                if (user.UserName == item.UserName)
                {
                    check = true;
                    break;
                }
            }
            if (ModelState.IsValid)
            {
                if (check)
                {
                    ModelState.AddModelError("", "UserName da ton tai");
                }
                else
                {
                    SetAlert("Them User thanh cong", "success");
                    user.PassWord = Encriptor.MD5Hash(user.PassWord);

                    db.Users.Add(user);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            return(View(user));
        }
예제 #3
0
 public ActionResult AddNewCourse(CourseViewModel model)
 {
     if (!ModelState.IsValid)
     {
         throw new Exception();
     }
     using (_db)
     {
         Course newCourse = new Course()
         {
             Title       = model.Title,
             Description = model.Description,
             Id          = model.Id,
             Teacher     = model.Teacher
         };
         //string newItem = Request.Form["newItem"];
         if (newCourse.Title.IsNullOrWhiteSpace())
         {
             return(RedirectToAction("AddNewCourse"));
         }
         var dbList = _db.courses.Create();
         dbList.Title = newCourse.Title;
         _db.courses.Add(dbList);
         _db.SaveChanges();
     }
     return(RedirectToAction("CourseIndex"));
 }
        protected override void Seed(Dbcontext context)
        {
            var users = new List <User>
            {
                new User {
                    Email = "*****@*****.**", FirstName = "abc", LastName = "def", Password = "******", ModifiedOn = DateTime.Now, CreatedOn = DateTime.Now
                }
            };

            users.ForEach(s => context.Users.AddOrUpdate(s));
            context.SaveChanges();

            var events = new List <BookReadingEvent>
            {
                new BookReadingEvent {
                    ModifiedOn = DateTime.Now, CreatedOn = DateTime.Now, BookTitle = "RishavBook", Date = DateTime.Now, Location = "Best PG", StartTime = "1", Type = Shared.CustomDataTypes.EventType.Public, UserID = 1
                }
            };

            events.ForEach(s => context.BookReadingEvents.AddOrUpdate(s));
            context.SaveChanges();
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
        }
예제 #5
0
        public ActionResult Create([Bind(Include = "ID,Name,MetaTitle,ParentID,DisplayOrder,SeoTitle,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,ShowOnHome")] ProductCategory productCategory)
        {
            if (ModelState.IsValid)
            {
                db.ProductCategories.Add(productCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productCategory));
        }
예제 #6
0
        public ActionResult Create([Bind(Include = "ID,Name,Code,MetaTitle,Description,Image,MoreImages,Price,PromotionPrice,IncludeVAT,Quantity,CategoryID,Detail,Warranty,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,TopHot,ViewCount")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
예제 #7
0
        public ActionResult Create([Bind(Include = "ID,CreateDate,CustomerID,ShipName,ShipMobile,ShipAddress,ShipEmail,Status")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(order));
        }
예제 #8
0
        public ActionResult Create([Bind(Include = "ProductID,OrderID,ProductName,Quantity,Price")] OrderDetail orderDetail)
        {
            if (ModelState.IsValid)
            {
                db.OrderDetails.Add(orderDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(orderDetail));
        }
 public bool Create(ProductCategory pc)
 {
     try
     {
         db.ProductCategories.Add(pc);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #10
0
 public bool Create(User model)
 {
     try
     {
         db.Users.Add(model);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #11
0
        // upload account balance
        public string UploadBalance(accountbalance accountBalance)
        {
            DbContext.accountbalances.Add(accountBalance);
            int result = DbContext.SaveChanges();

            if (result != 0)
            {
                return("uploaded succesfully");
            }
            else
            {
                return("An error occured");
            }
        }
예제 #12
0
 public long Create(Order order)
 {
     try
     {
         order.Status      = false;
         order.CreatedDate = DateTime.Now;
         db.Orders.Add(order);
         db.SaveChanges();
         return(order.OrderID);
     }
     catch
     {
         return(-1);
     }
 }
예제 #13
0
        // add user method
        public string AddUser(user user)
        {
            // add new user to the db
            DbContext.users.Add(user);
            int result = DbContext.SaveChanges();

            if (result != 0)
            {
                return("User Added succesfully");
            }
            else
            {
                return("An error occured.Please try again");
            }
        }
예제 #14
0
        /// <summary>
        /// 提交当前操作的结果
        /// </summary>
        public int Commit()
        {
            try
            {
                int returnValue = Dbcontext.SaveChanges();
                if (DbTransaction != null)
                {
                    DbTransaction.Commit();
                    this.Close();
                }
                return(returnValue);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException.InnerException is SqlException)
                {
                    SqlException sqlEx = ex.InnerException.InnerException as SqlException;
                    string       msg   = ExceptionMessageHelper.GetSqlExceptionMessage(sqlEx.Number);

                    throw DataAccessException.ThrowDataAccessException(sqlEx, msg);
                }

                throw;
            }
            finally
            {
                if (DbTransaction == null)
                {
                    this.Close();
                }
            }
        }
예제 #15
0
        //update list image
        public void UpdateImages(long ProductId, string images)
        {
            var product = db.Products.Find(ProductId);

            product.MoreImages = images;
            db.SaveChanges();
        }
예제 #16
0
        public ActionResult SignUp(FormCollection formdata)
        {
            Dbcontext db = new Dbcontext();
            User      u  = new User();

            if (ModelState.IsValid)
            {
                try
                {
                    u.Fullname        = Convert.ToString(formdata["Fullname"]);
                    u.Email           = Convert.ToString(formdata["Email"]);
                    u.Loginid         = Convert.ToString(formdata["Loginid"]);
                    u.DateofBirth     = Convert.ToDateTime(formdata["DateofBirth"]);
                    u.Password        = Convert.ToString(formdata["Password"]);
                    u.ConfirmPassword = Convert.ToString(formdata["ConfirmPassword"]);
                    u.State           = Convert.ToString(formdata["State"]);
                    u.MobileNo        = Convert.ToInt64(formdata["MobileNo"]);
                    u.City            = formdata["City"];
                    u.Cnic            = Convert.ToInt64(formdata["Cnic"]);
                    u.Gender          = new Gender {
                        Id = Convert.ToInt32(formdata["gender.Name"])
                    };
                    u.Role = new Role()
                    {
                        Id = 2
                    };
                    u.Shift       = formdata["Shift"];
                    u.FullAddress = formdata["FullAddress"];
                    int  counter = 0;
                    long uno     = DateTime.Now.Ticks;

                    foreach (string fileName in Request.Files)
                    {
                        HttpPostedFileBase file = Request.Files[fileName];
                        if (!string.IsNullOrEmpty(file.FileName))
                        {
                            string abc = uno + "_" + ++counter +
                                         file.FileName.Substring(file.FileName.LastIndexOf("."));
                            string url  = "~/Content/Images/" + abc;
                            string path = Request.MapPath(url);
                            u.ImageUrl = abc;
                            file.SaveAs(path);
                        }
                    }
                    db.Users.Add(u);
                    db.Entry(u.Role).State   = EntityState.Unchanged;
                    db.Entry(u.Gender).State = EntityState.Unchanged;
                    db.SaveChanges();
                    return(RedirectToAction("Login", "Users"));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                return(null);
            }
        }
예제 #17
0
        public ActionResult UpdateUser(User user)
        {
            Dbcontext db = new Dbcontext();

            using (db)
            {
                int  counter = 0;
                long uno     = DateTime.Now.Ticks;

                foreach (string fileName in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fileName];
                    if (!string.IsNullOrEmpty(file.FileName))
                    {
                        string abc = uno + "_" + ++counter +
                                     file.FileName.Substring(file.FileName.LastIndexOf("."));

                        string url  = "~/Content/Images/" + abc;
                        string path = Request.MapPath(url);
                        user.ImageUrl = abc;
                        file.SaveAs(path);
                    }
                }
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("UserDetails", "Admin"));
        }
예제 #18
0
 public void EditLink(ViewEditLink viewLink)
 {
     try
     {
         Link link = db.link.FirstOrDefault(p => p.id == viewLink.id);
         link.title           = viewLink.title;
         link.url             = viewLink.url;
         db.Entry(link).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         System.ArgumentException argEx = new System.ArgumentException(ex.Message);
         throw argEx;
     }
 }
        public ActionResult AddImages(Image images)
        {
            Dbcontext db      = new Dbcontext();
            int       counter = 0;
            long      uno     = DateTime.Now.Ticks;

            foreach (string fileName in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[fileName];
                if (!string.IsNullOrEmpty(file.FileName))
                {
                    string abc = uno + "_" + ++counter +
                                 file.FileName.Substring(file.FileName.LastIndexOf("."));
                    string url  = "~/Content/GalleryImages/" + abc;
                    string path = Request.MapPath(url);
                    images.ImageUrl = abc;
                    file.SaveAs(path);
                }
            }

            using (db)
            {
                db.Images.Add(images);
                db.SaveChanges();
            }
            return(View());
        }
예제 #20
0
        public ActionResult AddMember(FormCollection formdata)
        {
            Dbcontext dbcontext = new Dbcontext();
            Member    member    = new Member();

            if (ModelState.IsValid)
            {
                try
                {
                    member.FullName = formdata["FullName"];
                    member.CNIC     = Convert.ToInt64(formdata["CNIC"]);
                    member.MobileNo = Convert.ToInt64(formdata["MobileNo"]);
                    member.Gender   = new Gender {
                        Id = Convert.ToInt32(formdata["Gender.Name"])
                    };
                    member.Instructer = new Instructer {
                        Id = Convert.ToInt32(formdata["instructor"])
                    };
                    member.FullAddress    = formdata["FullAddress"];
                    member.DateofBirth    = Convert.ToDateTime(formdata["DateofBirth"]);
                    member.CurrentDate    = Convert.ToDateTime(formdata["CurrentDate"]);
                    member.Fee            = Convert.ToInt32(formdata["Fee"]);
                    member.SubmissionDate = Convert.ToDateTime(formdata["SubmissionDate"]);
                    member.SubmitTo       = formdata["SubmitTo"];
                    member.RollNo         = Convert.ToInt32(formdata["RollNo"]);
                    int  counter = 0;
                    long uno     = DateTime.Now.Ticks;

                    foreach (string fileName in Request.Files)
                    {
                        HttpPostedFileBase file = Request.Files[fileName];
                        if (!string.IsNullOrEmpty(file.FileName))
                        {
                            string abc = uno + "_" + ++counter +
                                         file.FileName.Substring(file.FileName.LastIndexOf("."));

                            string url  = "~/Content/MemberPics/" + abc;
                            string path = Request.MapPath(url);
                            member.ImageUrl = abc;
                            file.SaveAs(path);
                        }
                    }
                    dbcontext.Members.Add(member);
                    dbcontext.Entry(member.Gender).State     = EntityState.Unchanged;
                    dbcontext.Entry(member.Instructer).State = EntityState.Unchanged;
                    dbcontext.SaveChanges();
                    return(RedirectToAction("Message"));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
            return(View());
        }
예제 #21
0
 public bool AddUser(User user)
 {
     if (!db.users.Any(p => p.eamil == user.eamil))
     {
         db.users.Add(user);
         db.SaveChanges();
         return(true);
     }
     return(false);
 }
예제 #22
0
        public ActionResult SubmitMessage(Contact contact)
        {
            Dbcontext db = new Dbcontext();

            using (db)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("SuccessMessage", "Contact"));
            }
        }
예제 #23
0
        public ActionResult UpdateInstructor(Instructer instructer)
        {
            Dbcontext db = new Dbcontext();

            using (db)
            {
                db.Entry(instructer).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "Instructor"));
            }
        }
예제 #24
0
        public ActionResult DeleteAttandance(int id)
        {
            Dbcontext  db = new Dbcontext();
            Attandance p  = (from c in db.Attandances
                             where c.Id == id
                             select c).FirstOrDefault();

            db.Entry(p).State = EntityState.Deleted;
            db.SaveChanges();
            return(Json("Delete", JsonRequestBehavior.AllowGet));
        }
예제 #25
0
        public ActionResult SelectInstructor(int id)
        {
            Dbcontext db     = new Dbcontext();
            Member    member = new Member();

            using (db)
            {
                db.Members.Add(member);
                db.SaveChanges();
                return(RedirectToAction("HireSuccess", "Instructor"));
            }
        }
예제 #26
0
        public ActionResult DeleteUser(string id)
        {
            var userToRemove = db.Users.Find(id);

            if (userToRemove == null)
            {
                return(HttpNotFound());
            }
            db.Users.Remove(userToRemove);
            db.SaveChanges();
            return(RedirectToAction("UserList"));
        }
예제 #27
0
        public ActionResult DeleteMember(int id)
        {
            Dbcontext db     = new Dbcontext();
            Member    member = (from c in db.Members
                                .Include(x => x.Gender)
                                where c.Id == id
                                select c).FirstOrDefault();

            db.Entry(member).State = EntityState.Deleted;
            db.SaveChanges();
            return(Json("Delete", JsonRequestBehavior.AllowGet));
        }
        public ActionResult DeleteVideo(int id)
        {
            Dbcontext db = new Dbcontext();

            using (db)
            {
                Video video = (from c in db.Videos where c.Id == id select c).FirstOrDefault();
                db.Entry(video).State = EntityState.Deleted;
                db.SaveChanges();
            }
            return(Json("Delete", JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddVideos(FormCollection data, Video video)
        {
            video.AddDays = data["AddDays"];
            Dbcontext db = new Dbcontext();

            using (db)
            {
                db.Videos.Add(video);
                db.SaveChanges();
            }
            return(View());
        }
예제 #30
0
 public bool Insert(OrderDetail orderDetail)
 {
     try
     {
         db.OrderDetails.Add(orderDetail);
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }