public IHttpActionResult PutItem_transcation_inventory(int id, Item_transcation_inventory item_transcation_inventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != item_transcation_inventory.Seq)
            {
                return(BadRequest());
            }

            db.Entry(item_transcation_inventory).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Item_transcation_inventoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public void Delete(User user)
 {
     using (var dataContext = new SampleDBContext())
     {
         dataContext.Roles.RemoveRange(dataContext.Roles.Where(x => x.UserId == user.UserId));
         dataContext.SaveChanges();
         dataContext.Entry(user).State = EntityState.Deleted;
         dataContext.SaveChanges();
     }
 }
        public ActionResult Create([Bind(Include = "CustomerID,FirstName,LastName,Phone,Address,City,State,Zip")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Gender,Email")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Exemple #5
0
        public ActionResult Create([Bind(Include = "ID,Manufacturer,Name")] Car car)
        {
            if (ModelState.IsValid)
            {
                db.Cars.Add(car);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(car));
        }
Exemple #6
0
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Email,PhoneNumber,DateOfBirth,DrivingLicense,IsInternalEmployee")] tblEmployee tblEmployee)
        {
            if (ModelState.IsValid)
            {
                db.tblEmployees.Add(tblEmployee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tblEmployee));
        }
Exemple #7
0
        public ActionResult Create([Bind(Include = "ID,Name,Car")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
        public ActionResult Create([Bind(Include = "StudentId,StudentName,EmailId,Age,Location,DoJ,Department")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
 public void Update(User user)
 {
     using (var dataContext = new SampleDBContext())
     {
         dataContext.Roles.RemoveRange(dataContext.Roles.Where(x => x.UserId == user.UserId));
         dataContext.SaveChanges();
         if (user.Password == null)
         {
             var userDB = GetById(user.UserId);
             user.Password = userDB.Password;
         }
         dataContext.Users.Update(user);
         dataContext.SaveChanges();
     }
 }
Exemple #10
0
        public static void InsertTable(Item_transcation_inventory item)
        {
            SampleDBContext db = new SampleDBContext();

            db.Item_transcation_inventory.Add(item);
            db.SaveChanges();
        }
        public IActionResult Patch(int EmpId, /*string empname,*/ [FromBody] Employee employee)
        {
            Response <List <Employee> > employeeObj = new Response <List <Employee> >();
            SampleDBContext             responseObj = new SampleDBContext();

            try
            {
                using (var test = new SampleDBContext())
                {
                    var updateRecord = test.Employee.FirstOrDefault(t => t.EmpId == EmpId);
                    updateRecord.Name = employee.Name;   // Testcase1: If user try to update city column, there will be mismatch error with the body input
                    test.SaveChanges();

                    employeeObj.Status  = HttpStatusCode.OK;
                    employeeObj.Message = "record updated successfully";
                    return(Ok(employeeObj));
                }
            }
            catch
            {
                employeeObj.Status  = HttpStatusCode.NotFound;
                employeeObj.Message = "you have given wrong input";
                return(NotFound(employeeObj));
            }
        }
        public IActionResult Put(int EmpId, [FromBody] Employee employees)
        {
            SampleDBContext             responseObj = new SampleDBContext();
            Response <List <Employee> > employeeObj = new Response <List <Employee> >();

            // List<Employee> Object1 = new List<Employee>();
            try
            {
                using (var test = new SampleDBContext())
                {
                    var newRecord = test.Employee.Where(t => t.EmpId == EmpId).FirstOrDefault();
                    // var newRecord = (from c in test.Employee where c.Equals(EmpId) select c).ToList();
                    if (newRecord != null)
                    {
                        newRecord.Name   = employees.Name;
                        newRecord.City   = employees.City;
                        newRecord.DeptId = employees.DeptId;
                        //test.Employee.Update(employees);
                        test.SaveChanges();
                    }
                    return(Ok(employeeObj));
                }
            }
            catch (Exception ex)
            {
                //return NotFound();
                employeeObj.Status  = HttpStatusCode.NotFound;
                employeeObj.Message = "you have given wrong input";
                return(NotFound(employeeObj));
            }
        }
        public IActionResult Delete(int EmpId)
        {
            SampleDBContext             responseObj = new SampleDBContext();
            Response <List <Employee> > employeeObj = new Response <List <Employee> >();

            try
            {
                using (var test = new SampleDBContext())
                {
                    Employee employee = new Employee();

                    var record = test.Employee.Where(t => t.EmpId == EmpId).FirstOrDefault();

                    test.Employee.Remove(record);
                    test.SaveChanges();
                    return(Ok(responseObj));
                }
            }
            catch (Exception ex)
            {
                //return NotFound();

                employeeObj.Status  = HttpStatusCode.NotFound;
                employeeObj.Message = "you have given wrong input";
                return(NotFound(employeeObj));
            }
        }
        public IActionResult Insert([FromBody] Employee employee)
        {
            SampleDBContext             resposeObj  = new SampleDBContext();
            Response <List <Employee> > employeeObj = new Response <List <Employee> >();
            List <Employee>             Object1     = new List <Employee>();

            try
            {
                using (var test = new SampleDBContext())
                {
                    test.Employee.Add(employee);
                    test.SaveChanges();

                    employeeObj.Status  = HttpStatusCode.OK;
                    employeeObj.Message = "record displayed successfully";
                }
                return(Ok(employeeObj));
            }
            catch (Exception ex)
            {
                employeeObj.Status  = HttpStatusCode.NotFound;
                employeeObj.Message = "you have given wrong input";
                return(NotFound(employeeObj));
            }
        }
Exemple #15
0
        public static void DeleteTable(Item_transcation_inventory item)
        {
            SampleDBContext            db = new SampleDBContext();
            Item_transcation_inventory i  = db.Item_transcation_inventory.Find(item.SN);

            db.Item_transcation_inventory.Remove(i);
            db.SaveChanges();
        }
Exemple #16
0
        public ActionResult Comment(int id, string name, string email, string body)
        {
            Post post = GetPost(id);


            Comment comment = new Comment();

            comment.Post     = post;
            comment.Datetime = DateTime.Now;
            comment.Name     = name;
            comment.Email    = email;
            comment.Body     = body;
            model.Comments.Add(comment);
            model.SaveChanges();

            return(RedirectToAction("Details", new { id = id }));
        }
 /// <summary>
 /// Delete Employee by Id
 /// </summary>
 /// <param name="employeeId"></param>
 public void DeleteEmployee(int employeeId)
 {
     using (var context = new SampleDBContext())
     {
         var emp = context.Employees.Where(e => e.Id == employeeId).FirstOrDefault();
         context.Employees.Remove(emp);
         context.SaveChanges();
     }
 }
Exemple #18
0
 //Http Get for Delete
 public ActionResult DeleteRoom(int id)
 {
     if (Session["Admin_Name"] != null)
     {
         Guest_Info guest = db.guest_Info.Where(x => x.Room_No == id).FirstOrDefault();
         if (guest == null)
         {
             Hotel_Info hotel = db.hotel_Info.Find(id);
             db.hotel_Info.Remove(hotel);
             db.SaveChanges();
             TempData["SuccessMessage"] = "Are you sure to delete this record?";
             return(RedirectToAction("Index"));
         }
         TempData["AlertMessage"] = "You can't delete this data";
         return(RedirectToAction("Index"));
     }
     return(RedirectToAction("LogIn", "User"));
 }
 public void AddUser(User user)
 {
     user.Password = "******"; //Default password for all the users
     using (var dataContext = new SampleDBContext())
     {
         dataContext.Users.Add(user);
         dataContext.SaveChanges();
     }
 }
 //Delete User Account// Get
 public ActionResult DeleteUserAccount(int id)
 {
     if (Session["Admin_Name"] != null)
     {
         User user = new User();
         user = db.user.Find(id);
         db.user.Remove(user);
         db.SaveChanges();
         TempData["AlertMessage"] = "Are you sure to delete this user record?";
         return(RedirectToAction("Index"));
     }
     return(RedirectToAction("LogIn", "User"));
 }
        public ActionResult singleBooking(Guest_Info guest)
        {
            string paramID = RouteData.Values["id"].ToString();

            if (paramID == guest.Room_No.ToString())
            {
                if (ModelState.IsValid)
                {
                    db.guest_Info.Add(guest);
                    Hotel_Info hotel = db.hotel_Info.Where(x => x.Room_No == guest.Room_No).FirstOrDefault();
                    hotel.IsBooked = true;
                    db.SaveChanges();
                    int RoomNo;
                    if (guest.Room_No.HasValue)
                    {
                        RoomNo = (int)guest.Room_No;
                        userclassobject.addAllGuestInfo(RoomNo);
                    }
                    return(RedirectToAction("Index"));
                }
            }
            ModelState.AddModelError("", "Room No should not be changed. Input '" + paramID + "'");
            return(View(guest));
        }
Exemple #22
0
        public ActionResult Edit(Employee employee)
        {
            if (ModelState.IsValid)
            {
                SampleDBContext db             = new SampleDBContext();
                Employee        employeeFromDB = db.Employees.Single(x => x.Id == employee.Id);

                // Populate all the properties except EmailAddrees
                employeeFromDB.FullName        = employee.FullName;
                employeeFromDB.Gender          = employee.Gender;
                employeeFromDB.Age             = employee.Age;
                employeeFromDB.HireDate        = employee.HireDate;
                employeeFromDB.Salary          = employee.Salary;
                employeeFromDB.PersonalWebSite = employee.PersonalWebSite;

                db.Entry(employeeFromDB).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = employee.Id }));
            }
            return(View(employee));
        }
Exemple #23
0
 public int Insert(Car e)
 {
     context.Cars.Add(e);
     return(context.SaveChanges());
 }
Exemple #24
0
 public int Insert(Rental c)
 {
     context.Rentals.Add(c);
     return(context.SaveChanges());
 }
 public void Add(Sample sample)
 {
     _ctx.Samples.Add(sample);
     _ctx.SaveChanges();
 }
Exemple #26
0
 public void Save()
 {
     context.SaveChanges();
 }
Exemple #27
0
        static void Main(string[] args)
        {
            using (SampleDBContext BlogDBContext = new SampleDBContext())
            {
                BlogDBContext.Set <Publisher>().Add(new Publisher()
                {
                    Name  = "测试发布者",
                    Blogs = new List <Blog>()
                    {
                        new Blog()
                        {
                            Content = "测试博客 A"
                        },
                        new Blog()
                        {
                            Content = "测试博客 B"
                        },
                        new Blog()
                        {
                            Content = "测试博客 C"
                        },
                    }
                });
                BlogDBContext.SaveChanges();

                /* 存在外键约束,博客的PublisherID必须为数据库内当前已经存在的值,
                 *  需要先保存发布者信息至数据库,否则空降博客会导致外键约束失败 */
                BlogDBContext.Blogs.Add(
                    new Blog()
                {
                    Content     = "空降一篇博客",
                    PublisherID = BlogDBContext.Publishers.First(Publisher => Publisher.Name == "测试发布者").PublisherID
                });

                /* 存在外键约束,博客的PublisherID必须为数据库内当前已经存在的值,
                 *  下面使用 PublisherID=10101 发布博客将会失败 */
                //BlogDBContext.Blogs.Add(new Blog() { Content = "幽灵博客", PublisherID=10101});
                BlogDBContext.SaveChanges();

                //!!! 解决延迟加载导致空对象问题:在目标数据表后使用 .Include("扩展数据表") 包含扩展数据表即可,此方法包含在 Microsoft.EntityFrameworkCore 命名空间需要 using ;
                //foreach (Publisher publisher in BlogDBContext.Publishers.Include("Blogs"))
                //    Console.WriteLine(publisher.Name + " " + publisher.Blogs.Count);

                Console.WriteLine("《测试博客 B》 的发布者为 : " + BlogDBContext.Blogs.First(Blog => Blog.Content == "测试博客 B").Publisher.Name);
                //TODO: 遗留问题-1:通过种子数据添加的 BlogDBContext.Publishers.First(Publisher => Publisher.Name == "测试发布者").Blogs.Count 会输出 1 (应为4)
                //Console.WriteLine($"测试发布者 发布了 {BlogDBContext.Blogs.Where(blog => blog.PublisherID == BlogDBContext.Publishers.FirstOrDefault(publisher => publisher.Name == "测试发布者").PublisherID).Count()} 篇博客。");
                Console.WriteLine($"种子发布者-2 发布了 {BlogDBContext.Publishers.First(Publisher => Publisher.Name == "种子发布者-2")?.Blogs?.Count.ToString()??"*"} 篇博客。");

                Console.WriteLine(string.Empty);
                Console.WriteLine("Blogs.Count : " + BlogDBContext.Blogs.Count().ToString());
                Console.WriteLine("Blogs :");
                //TODO: 遗留问题-2:通过种子数据添加的{blog.Publisher?.Name ?? "*"} 会输出 * (应为博客发布者名称)
                foreach (Blog blog in BlogDBContext.Blogs)
                {
                    Console.WriteLine($"\t{blog.Content} \tvia : {blog.Publisher?.Name ?? "*"}\t(ID : {blog.PublisherID})");
                }
                //Console.WriteLine($"\t{blog.Content} \tvia : {BlogDBContext.Publishers.First(publisher => publisher.PublisherID == blog.PublisherID).Name}\t(ID : {blog.PublisherID})");

                Console.WriteLine(string.Empty);
                Console.WriteLine("Publishers.Count : " + BlogDBContext.Publishers.Count().ToString());
                Console.WriteLine("Publishers :");
                foreach (Publisher publisher in BlogDBContext.Publishers)
                {
                    Console.WriteLine($"\t{publisher.Name} \t(ID : {publisher.PublisherID})\t发布数 : {publisher.Blogs.Count}");
                }
            }

            Console.Read();
        }
Exemple #28
0
 public int Insert(User e)
 {
     context.Users.Add(e);
     // context.Logins.Add(l);
     return(context.SaveChanges());
 }
        public void Fabricantes_Incluir()
        {
            _fabricanteRepository.Create(new Fabricante("Dell"));
            _fabricanteRepository.Create(new Fabricante("Sansumg"));
            _fabricanteRepository.Create(new Fabricante("LG"));
            _context.SaveChanges();

            var count = _fabricanteRepository.GetAll().Count();

            Assert.AreEqual(3, count);
        }