示例#1
0
        public void Create(ProductViewModel product)
        {
            var entity = new Product();

            entity.ProductName  = product.ProductName;
            entity.UnitPrice    = product.UnitPrice;
            entity.UnitsInStock = (short)product.UnitsInStock;
            entity.Discontinued = product.Discontinued;
            entity.CategoryID   = product.CategoryID;

            if (entity.CategoryID == null)
            {
                entity.CategoryID = 1;
            }

            if (product.Category != null)
            {
                entity.CategoryID = product.Category.CategoryID;
            }

            entities.Products.Add(entity);
            entities.SaveChanges();

            product.ProductID = entity.ProductID;
        }
示例#2
0
        public virtual void Insert(OrgChartConnection connection, ModelStateDictionary modelState)
        {
            db.OrgChartConnections.Add(connection);
            db.SaveChanges();

            connection.Id = connection.Id;
        }
示例#3
0
        public IHttpActionResult PutDepartment(int id, Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != department.deptid)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#4
0
        public IHttpActionResult PutCarMake(int id, CarMake carMake)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != carMake.ID)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
示例#5
0
        public Models.TokenEntities GenerateToken(int userId)
        {
            string   token     = Guid.NewGuid().ToString();
            DateTime issuedOn  = DateTime.Now;
            DateTime expiredOn = DateTime.Now.AddSeconds(
                Convert.ToDouble(ConfigurationManager.AppSettings["AuthTokenExpiry"]));
            var tokendomain = new Token
            {
                UserId    = userId,
                AuthToken = token,
                IssuedOn  = issuedOn,
                ExpiresOn = expiredOn
            };

            db.Tokens.Add(tokendomain);
            db.SaveChanges();
            //_unitOfWork.TokenRepository.Insert(tokendomain);
            //_unitOfWork.Save();


            var tokenModel = new TokenEntities()
            {
                UserId    = userId,
                IssuedOn  = issuedOn,
                ExpiresOn = expiredOn,
                AuthToken = token
            };

            return(tokenModel);
        }
示例#6
0
        public virtual void Insert(OrgChartShape shape, ModelStateDictionary modelState)
        {
            db.OrgChartShapes.Add(shape);
            db.SaveChanges();

            shape.Id = shape.Id;
        }
        public virtual void Insert(MeetingViewModel meeting, ModelStateDictionary modelState)
        {
            if (ValidateModel(meeting, modelState))
            {
                if (meeting.Attendees == null)
                {
                    meeting.Attendees = new int[0];
                }

                if (string.IsNullOrEmpty(meeting.Title))
                {
                    meeting.Title = "";
                }

                var entity = meeting.ToEntity();

                foreach (var attendeeId in meeting.Attendees)
                {
                    entity.MeetingAttendees.Add(new MeetingAttendee
                    {
                        AttendeeID = attendeeId
                    });
                }

                db.Meetings.Add(entity);
                db.SaveChanges();

                meeting.MeetingID = entity.MeetingID;
            }
        }
示例#8
0
        public virtual void Insert(DependencyViewModel dependency, ModelStateDictionary modelState)
        {
            var entity = dependency.ToEntity();

            db.GanttDependencies.Add(entity);
            db.SaveChanges();

            dependency.DependencyID = entity.ID;
        }
示例#9
0
        public virtual void Insert(ResourceAssignmentViewModel assignment)
        {
            var entity = assignment.ToEntity();

            db.GanttResourceAssignments.Add(entity);
            db.SaveChanges();

            assignment.ID = entity.ID;
        }
        public ActionResult DeleteConfirmed(int id)
        {
            PatientOrder patOrder = new PatientOrder();

            PatientOrder patientOrder = db.PatientOrders.SingleOrDefault(p => p.PatientOrderId == id);

            db.PatientOrders.Remove(patientOrder);
            TryUpdateModel <PatientOrder>(patOrder);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Create(Document document)
 {
     if (ModelState.IsValid)
     {
         db.Documents.Add(document);
         db.SaveChanges();
         Index(document, "create");
         return(RedirectToAction("Index"));
     }
     return(View(document));
 }
示例#12
0
 public ActionResult Addplatter(tbl_platter model1, HttpPostedFileBase image1)
 {
     if (image1 != null)
     {
         model1.platter_image = new byte[image1.ContentLength];
         image1.InputStream.Read(model1.platter_image, 0, image1.ContentLength);
     }
     db.tbl_platter.Add(model1);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#13
0
        public void Create(ProductVM product)
        {
            Product pd = new Product();

            //pd.Id = 5;
            pd.Name     = product.Name;
            pd.Category = product.Category;
            pd.Price    = product.Price;
            dbcontext.Products.Add(pd);
            dbcontext.SaveChanges();
        }
示例#14
0
        public ActionResult Create([Bind(Include = "ID,Name")] CarMake carMake)
        {
            if (ModelState.IsValid)
            {
                db.CarMakes.Add(carMake);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(carMake));
        }
示例#15
0
        public virtual void Insert(EmployeeDirectoryModel employee, ModelStateDictionary modelState)
        {
            if (ValidateModel(employee, modelState))
            {
                var entity = employee.ToEntity();

                db.EmployeeDirectory.Add(entity);
                db.SaveChanges();

                employee.EmployeeId = entity.EmployeeID;
            }
        }
示例#16
0
        public TblProductList Add(TblProductList item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            // TO DO : Code to save record into database
            ProductDB.TblProductLists.Add(item);
            ProductDB.SaveChanges();
            return(item);
        }
示例#17
0
        public void Create(ProductViewModel product)
        {
            if (!UpdateDatabase)
            {
                var first = GetAll().OrderByDescending(e => e.ProductID).FirstOrDefault();
                var id    = (first != null) ? first.ProductID : 0;

                product.ProductID = id + 1;

                if (product.CategoryID == null)
                {
                    product.CategoryID = 1;
                }

                if (product.Category == null)
                {
                    product.Category = new CategoryViewModel()
                    {
                        CategoryID = 1, CategoryName = "Beverages"
                    };
                }

                GetAll().Insert(0, product);
            }
            else
            {
                var entity = new Product();

                entity.ProductName  = product.ProductName;
                entity.UnitPrice    = product.UnitPrice;
                entity.UnitsInStock = (short)product.UnitsInStock;
                entity.Discontinued = product.Discontinued;
                entity.CategoryID   = product.CategoryID;

                if (entity.CategoryID == null)
                {
                    entity.CategoryID = 1;
                }

                if (product.Category != null)
                {
                    entity.CategoryID = product.Category.CategoryID;
                }

                entities.Products.Add(entity);
                entities.SaveChanges();

                product.ProductID = entity.ProductID;
            }
        }
示例#18
0
        //public ActionResult Index()
        //{
        //    //List<tblPerson> obj = new List<tblPerson>();
        //    //var data = db.spGetPersonByCountry("India").ToList();
        //    //obj = db.GetPersonByCountry("India").ToList();

        //    //int Count = 0;
        //    //ObjectParameter returnCount= new ObjectParameter("PersonCount", typeof(Int32));
        //    //db.spGetPersonCountByCountry(returnCount, "India");
        //    ////var PersonCountByCountry = db.GetPersonCountByCountry(, "London");
        //    ////var value = Request.Cookies["UserInformation"].Values;
        //    ////HttpCookie ck = new HttpCookie("UserInformation");
        //    ////ck.Values.Add("Username", "*****@*****.**");
        //    ////ck.Values.Add("Password", "12345678");
        //    ////Response.Cookies.Add(ck);

        //    //return RedirectToAction("Login", "Account");
        //}

        public ActionResult CreateStickyNote(stickyNote stickynote)
        {
            StickyNote obj = new StickyNote();

            obj.Text   = stickynote.text;
            obj.Left   = stickynote.left;
            obj.Top    = stickynote.top;
            obj.Colour = stickynote.colour;
            obj.Width  = stickynote.width;
            obj.Height = stickynote.height;
            db.StickyNotes.Add(obj);
            db.SaveChanges();
            return(Json(obj.Id, JsonRequestBehavior.AllowGet));
        }
        public static void Insert(EmployeeDirectoryModel employee)
        {
            if (!UpdateDatabase)
            {
                var first = All().OrderByDescending(e => e.EmployeeId).FirstOrDefault();

                var id = 0;

                if (first != null)
                {
                    id = first.EmployeeId;
                }

                employee.EmployeeId = id + 1;

                All().Insert(0, employee);
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    var entity = employee.ToEntity();

                    db.EmployeeDirectory.AddObject(entity);
                    db.SaveChanges();

                    employee.EmployeeId = entity.EmployeeID;
                }
            }
        }
示例#20
0
 public ActionResult Products_Update([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
 {
     if (ModelState.IsValid)
     {
         using (var northwind = new SampleEntities())
         {
             // Create a new Product entity and set its properties from the posted ProductViewModel.
             var entity = new Product
             {
                 ProductID    = product.ProductID,
                 ProductName  = product.ProductName,
                 UnitsInStock = product.UnitsInStock
             };
             // Attach the entity.
             northwind.Products.Attach(entity);
             // Change its state to Modified so Entity Framework can update the existing product instead of creating a new one.
             northwind.Entry(entity).State = EntityState.Modified;
             // Or use ObjectStateManager if using a previous version of Entity Framework.
             // northwind.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
             // Update the entity in the database.
             northwind.SaveChanges();
         }
     }
     // Return the updated product. Also return any validation errors.
     return(Json(new[] { product }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
 }
示例#21
0
 public ActionResult Products_Destroy([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
 {
     if (ModelState.IsValid)
     {
         using (var northwind = new SampleEntities())
         {
             // Create a new Product entity and set its properties from the posted ProductViewModel.
             var entity = new Product
             {
                 ProductID    = product.ProductID,
                 ProductName  = product.ProductName,
                 UnitsInStock = product.UnitsInStock
             };
             // Attach the entity.
             northwind.Products.Attach(entity);
             // Delete the entity.
             northwind.Products.Remove(entity);
             // Or use DeleteObject if using a previous versoin of Entity Framework.
             // northwind.Products.DeleteObject(entity);
             // Delete the entity in the database.
             northwind.SaveChanges();
         }
     }
     // Return the removed product. Also return any validation errors.
     return(Json(new[] { product }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
 }
示例#22
0
        public override Task OnConnected()
        {
            var name = Context.User.Identity.Name;

            using (var db = new SampleEntities())
            {
                var user = db.UserSet
                           .SingleOrDefault(u => u.UserName == name);

                if (user == null)
                {
                    user = new User
                    {
                        UserName   = name,
                        Connection = new List <Connection>()
                    };
                    db.UserSet.Add(user);
                }

                user.Connection.Add(new Connection
                {
                    ConnectionId = Context.ConnectionId,
                    Connected    = true
                });
                db.SaveChanges();
            }
            return(base.OnConnected());
        }
        public static void Insert(OrgChartShape shape)
        {
            if (!UpdateDatabase)
            {
                var first = All().OrderByDescending(e => e.Id).FirstOrDefault();

                var id = 0;

                if (first != null)
                {
                    id = first.Id;
                }

                shape.Id = id + 1;

                All().Insert(0, shape);
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    db.OrgChartShapes.AddObject(shape);
                    db.SaveChanges();
                }
            }
        }
        /// <summary>
        /// Saves the import data.
        /// </summary>
        /// <param name="importZipCodes">The import zip codes.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void SaveImportData(IEnumerable <TaiwanZipCode> importZipCodes)
        {
            try
            {
                //先砍掉全部資料
                using (var db = new SampleEntities())
                {
                    foreach (var item in db.TaiwanZipCodes.OrderBy(x => x.ID))
                    {
                        db.TaiwanZipCodes.Remove(item);
                    }
                    db.SaveChanges();
                }

                //再把匯入的資料給存到資料庫
                using (var db = new SampleEntities())
                {
                    foreach (var item in importZipCodes)
                    {
                        db.TaiwanZipCodes.Add(item);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#25
0
        public static void Update(OrgChartConnection connection)
        {
            if (!UpdateDatabase)
            {
                var target = One(e => e.Id == connection.Id);

                if (target != null)
                {
                    target.FromShapeId = connection.FromShapeId;
                    target.ToShapeId   = connection.ToShapeId;
                    target.Text        = connection.Text;
                    target.FromPointX  = connection.FromPointX;
                    target.FromPointY  = connection.FromPointY;
                    target.ToPointX    = connection.ToPointX;
                    target.ToPointY    = connection.ToPointY;
                }
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    db.OrgChartConnections.Attach(connection);
                    db.ObjectStateManager.ChangeObjectState(connection, EntityState.Modified);
                    db.SaveChanges();
                }
            }
        }
示例#26
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (SampleEntities en = new SampleEntities())
         {
             var entity = en.ADPFileDb.FirstOrDefault(i => i.Id == id);
             if (entity != null)
             {
                 File.Delete(entity.Location);
                 en.ADPFileDb.Remove(entity);
                 en.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The specified ID does not exist!!!"));
             }
         }
     }
     catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
     }
 }
示例#27
0
 public HttpResponseMessage Put(string fname, ADPFileDb d)
 {
     try
     {
         using (SampleEntities en = new SampleEntities())
         {
             var entity = en.ADPFileDb.FirstOrDefault(i => i.FileName == fname);
             if (entity != null)
             {
                 entity.UserName = d.UserName;
                 entity.Date     = d.Date;
                 en.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.Created, entity));
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The specified ID does not exist!!!"));
             }
         }
     }
     catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
     }
 }
示例#28
0
        public ActionResult Create(Comment collection)
        {
            try
            {
                // TODO: Add insert logic here
                objent.Comments.Add(collection);
                objent.SaveChanges();
                List <Comment> list = new List <Comment>();
                if (Request.IsAjaxRequest())
                {
                    list = objent.Comments.ToList();


                    return(View("LstC", list));
                }
                else
                {
                    return(View(list));
                }
            }
            catch
            {
                return(View());
            }
        }
示例#29
0
        public static void Update(GanttTaskModel task)
        {
            if (!UpdateDatabase)
            {
                var target = One(e => e.ID == task.ID);

                if (target != null)
                {
                    target.Title           = task.Title;
                    target.Start           = task.Start;
                    target.End             = task.End;
                    target.PercentComplete = task.PercentComplete;
                    target.OrderID         = task.OrderID;
                    target.ParentID        = task.ParentID;
                    target.Summary         = task.Summary;
                    target.Expanded        = task.Expanded;
                }
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    var entity = task.ToEntity();

                    db.GanttTasks.Attach(entity);
                    db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);

                    db.SaveChanges();
                }
            }
        }
        public static void Update(EmployeeDirectoryModel employee)
        {
            if (!UpdateDatabase)
            {
                var target = One(e => e.EmployeeId == employee.EmployeeId);

                if (target != null)
                {
                    target.FirstName = employee.FirstName;
                    target.LastName  = employee.LastName;
                    target.Address   = employee.Address;
                    target.City      = employee.City;
                    target.Country   = employee.Country;
                    target.Phone     = employee.Phone;
                    target.Extension = employee.Extension;
                    target.BirthDate = employee.BirthDate;
                    target.HireDate  = employee.HireDate;
                    target.Position  = employee.Position;
                    target.ReportsTo = employee.ReportsTo;
                }
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    var entity = employee.ToEntity();
                    db.EmployeeDirectory.Attach(entity);
                    db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
                    db.SaveChanges();
                }
            }
        }