public void UpdateSpecificationType(SpecificationType specificationType)
        {
            _context.SpecificationTypes.Attach(specificationType);
            _context.Entry(specificationType).State = EntityState.Modified;

            foreach (Specification specification in specificationType.Specifications)
            {
                _context.Specifications.Attach(specification);
            }

            _context.SaveChanges();
        }
 public ActionResult Edit([Bind(Include = "ContestPostId,Recipe,SubmitedAt,ContestId,UserId")] ContestPost contestPost)
 {
     if (ModelState.IsValid)
     {
         db.Entry(contestPost).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ContestId = new SelectList(db.Contests, "ContestId", "Title", contestPost.ContestId);
     ViewBag.UserId    = new SelectList(db.Users, "UserId", "Name", contestPost.UserId);
     return(View(contestPost));
 }
        public ActionResult Update(Account account)
        {
            var errors = ModelState
                         .Where(x => x.Value.Errors.Count > 0)
                         .Select(x => new { x.Key, x.Value.Errors })
                         .ToArray();

            if (ModelState.IsValid)
            {
                bool UniqueEmail    = true;
                bool UniqueUserName = true;


                foreach (Account u in db.Users)
                {
                    if (account.Email.ToString().Equals(u.Email.ToString()) && !account.UID.Equals(u.UID))
                    {
                        UniqueEmail = false;
                    }
                    if (account.Username.ToString().Equals(u.Username.ToString()) && !account.UID.Equals(u.UID))
                    {
                        UniqueUserName = false;
                    }
                }
                if (UniqueUserName && UniqueEmail)
                {
                    var updatedAccount = db.Users.Find(account.UID);
                    updatedAccount.FirstName       = account.FirstName;
                    updatedAccount.LastName        = account.LastName;
                    updatedAccount.Username        = account.Username;
                    updatedAccount.Email           = account.Email;
                    db.Entry(updatedAccount).State = EntityState.Modified;
                    db.SaveChanges();
                    ModelState.Clear();
                    TempData["message"] = account.FirstName + " " + account.LastName + " successfully updated";
                    return(View("Profile"));
                }
                else if (!UniqueUserName && UniqueEmail)
                {
                    ModelState.AddModelError("Username", "Username already exists.");
                }
                else if (UniqueUserName && !UniqueEmail)
                {
                    ModelState.AddModelError("Email", "Email Address already exists.");
                }
                else
                {
                    ModelState.AddModelError("Email", "Email Address already exists.");
                    ModelState.AddModelError("Username", "Username already exists.");
                }
            }
            return(View(account));
        }
 private void favouriteButton_Click(object sender, EventArgs e)
 {
     using (var context = new MyDbContext())
     {
         var user = context.Users.Find(UserId);
         var book = context.Books.Find(BookId);
         context.Entry(user).Collection("Books").Load();
         user.Books.Remove(book);
         context.SaveChanges();
         DownloadData();
     }
 }
示例#5
0
 public void UpdateFieldChangedOnly(Patient originalPatient, Patient newPatient)
 {
     try
     {
         db.Entry(originalPatient).CurrentValues.SetValues(newPatient);
         db.SaveChanges();
     }
     catch (DbEntityValidationException exp)
     {
         log.Error(exp);
     }
 }
示例#6
0
        public async Task UpdateEntity(int id, Folder Folder)
        {
            var entityExist = await EntitynameAlreadyExist(Folder.Name);

            if (entityExist == false)
            {
                var update = await _context.Entities.FirstOrDefaultAsync(c => c.FolderId == id);

                _context.Entry(update).CurrentValues.SetValues(Folder);
                await _context.SaveChangesAsync();
            }
        }
示例#7
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description,Thumbnail,Price,CategoryId,CreateDate,CreateBy,UpdateBy")] Product product)
 {
     product.UpdateDate = DateTime.Now;
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
     return(View(product));
 }
 public void UpdateFieldChangedOnly(Medicine originalMedicine, Medicine newMedicine)
 {
     try
     {
         db.Entry(originalMedicine).CurrentValues.SetValues(newMedicine);
         db.SaveChanges();
     }
     catch (DbEntityValidationException exp)
     {
         log.Error(exp);
     }
 }
 public ActionResult Edit([Bind(Include = "BookKeyWordID,BookCopyID,KeyWordID")] BookKeyWord bookKeyWord)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookKeyWord).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BookCopyID = new SelectList(db.BookCopies, "BookCopyID", "BookCopyID", bookKeyWord.BookCopyID);
     ViewBag.KeyWordID  = new SelectList(db.KeyWords, "KeyWordID", "KeyWordName", bookKeyWord.KeyWordID);
     return(View(bookKeyWord));
 }
示例#10
0
        public void UpdateCategory(Category category)
        {
            _context.Categories.Attach(category);
            _context.Entry(category).State = EntityState.Modified;

            foreach (Product product in category.Products)
            {
                _context.Products.Attach(product);
            }

            _context.SaveChanges();
        }
 public ActionResult Edit([Bind(Include = "ExamResultID,ExamDate,Score,ExamID,StudentID")] ExamResult examResult)
 {
     if (ModelState.IsValid)
     {
         db.Entry(examResult).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ExamID    = new SelectList(db.Exams, "ExamID", "Code", examResult.ExamID);
     ViewBag.StudentID = new SelectList(db.Students, "StudentID", "Firstname", examResult.StudentID);
     return(View(examResult));
 }
 public ActionResult Edit([Bind(Include = "Id,CourseId,StudentId,Grade")] Enrollment enrollment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(enrollment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseId  = new SelectList(db.Courses, "Id", "Title", enrollment.CourseId);
     ViewBag.StudentId = new SelectList(db.Students, "Id", "LastName", enrollment.StudentId);
     return(View(enrollment));
 }
示例#13
0
        public async Task <IActionResult> PutSupply(long id, Supply supply)
        {
            if (id != supply.ItemId)
            {
                return(BadRequest());
            }

            _context.Entry(supply).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
示例#14
0
 public ActionResult Edit([Bind(Include = "MessageID,Date,SenderID,ReceiverID,Text")] Message message)
 {
     if (ModelState.IsValid)
     {
         db.Entry(message).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ReceiverID = new SelectList(db.Users, "UserID", "Nick", message.ReceiverID);
     ViewBag.SenderID   = new SelectList(db.Users, "UserID", "Nick", message.SenderID);
     return(View(message));
 }
示例#15
0
        public ActionResult Edit([Bind(Include = "FacultyID,FacultyName")] Faculty faculty)
        {
            if (ModelState.IsValid)
            {
                db.Entry(faculty).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(faculty));
        }
示例#16
0
        public async Task <IActionResult> PutItem(long id, Item item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
示例#17
0
        public IActionResult Get(string typeString, string typeIdString)
        {
            //Validate type as PlayableType and typeId as GUID id:
            if (!Enum.TryParse(typeof(PlayableType), typeString, true, out object typeObject) ||
                !Guid.TryParse(typeIdString, out Guid typeId))
            {
                return(NotFound());
            }

            PlayableType type = (PlayableType)typeObject;

            //Get IPlayable for the given type and id:
            IPlayable iPlayable = null;

            if (type == PlayableType.Playlist)                                                //user playlist
            {
                iPlayable = _helper.GetUserPlaylistById(this.HttpContext, typeId.ToString()); //Check if user is authenticated and owns such playlist.
            }
            else if (type == PlayableType.PublicPlaylist)                                     //public playlist
            {
                iPlayable = _context.PublicPlaylists.FirstOrDefault(x => x.PublicPlaylistId == typeId);
            }
            else if (type == PlayableType.Album) //album
            {
                iPlayable = _context.Albums.Include(x1 => x1.Artist).FirstOrDefault(x => x.AlbumId == typeId);
            }

            if (iPlayable == null)
            {
                return(NotFound()); //no playable was found
            }
            //Load entry to access PlayableId
            _context.Entry(iPlayable).Reference(x => x.Playable).Load();

            //Load necessary related playable data (independent of playable type):
            iPlayable.Playable = _context.Playables
                                 .Include(x => x.PlayableSongs)
                                 .ThenInclude(x => x.Song)
                                 .ThenInclude(x => x.Video)
                                 .Include(x => x.PlayableSongs)
                                 .ThenInclude(x => x.Song)
                                 .ThenInclude(x => x.PublicSong)
                                 .ThenInclude(x => x.Album)
                                 .ThenInclude(x => x.Artist)
                                 .Include(x => x.PlayableSongs)
                                 .ThenInclude(x => x.Song)
                                 .ThenInclude(x => x.PrivateSong)
                                 .FirstOrDefault(x => x.PlayableId == iPlayable.Playable.PlayableId);

            PlayableVM playableVM = new PlayableVM(iPlayable);

            return(Ok(playableVM));
        }
示例#18
0
 public void UpdateFieldChangedOnly(Disease originalDisease, Disease newDisease)
 {
     try
     {
         db.Entry(originalDisease).CurrentValues.SetValues(newDisease);
         db.SaveChanges();
     }
     catch (DbEntityValidationException exp)
     {
         log.Error(exp);
     }
 }
 public ActionResult Edit([Bind(Include = "majorID,subjectNumber,subjectYear,subjectSemester")] majorSubject majorSubject)
 {
     if (ModelState.IsValid)
     {
         db.Entry(majorSubject).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.majorID       = new SelectList(db.majors, "majorId", "major1", majorSubject.majorID);
     ViewBag.subjectNumber = new SelectList(db.subjectLists, "subjectNumber", "subjectName", majorSubject.subjectNumber);
     return(View(majorSubject));
 }
示例#20
0
        public ActionResult Edit([Bind(Include = "Id,Name,Rating,DownloadURL,ImageUrl")]
                                 Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Entry(movie).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movie));
        }
示例#21
0
        public async Task <IHttpActionResult> Update([FromBody] RegStore model)
        {
            if (ModelState.IsValid)
            {
                var Username = User.Identity.GetUserName();
                model.Email           = Username;
                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(Ok());
        }
示例#22
0
        public async Task <IActionResult> PutWarehouse(long id, Warehouse warehouse)
        {
            if (id != warehouse.Id)
            {
                return(BadRequest());
            }

            _context.Entry(warehouse).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
示例#23
0
 public void UpdateFieldChangedOnly(Employee originalEmployee, Employee newEmployee)
 {
     try
     {
         db.Entry(originalEmployee).CurrentValues.SetValues(newEmployee);
         db.SaveChanges();
     }
     catch (DbEntityValidationException exp)
     {
         log.Error(exp);
     }
 }
 public ActionResult Edit([Bind(Include = "CodigoEmpleado,Nombre,Apellido,Telefono,codigoDepartamento,codigocargo,Fecha,Salario,Estatus")] Empleado empleado)
 {
     if (ModelState.IsValid)
     {
         db.Entry(empleado).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.codigocargo        = new SelectList(db.cargos, "codigocargo", "nombrecargo", empleado.codigocargo);
     ViewBag.codigoDepartamento = new SelectList(db.departamentos, "codigodepartamento", "nombredepartamento", empleado.codigoDepartamento);
     return(View(empleado));
 }
 public ActionResult Edit([Bind(Include = "Task_id,Task_Name,Task_description,Pro_id,User_Id,Due_date,Priority")] Tasktbl tasktbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tasktbl).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Pro_id  = new SelectList(db.projects, "Pro_id", "Project_Name", tasktbl.Pro_id);
     ViewBag.User_Id = new SelectList(db.users, "User_id", "User_name", tasktbl.User_Id);
     return(View(tasktbl));
 }
 public ActionResult Edit([Bind(Include = "Id,RoleId,PhoneNumber,FullName,UserName,EmailAddress,StatusId,UnitesSectionsId,SupervisorId")] Employee employee, int SupervisorOptions)
 {
     if (ModelState.IsValid)
     {
         employee.SupervisorId    = SupervisorOptions;
         employee.RoleId          = 2;
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
示例#27
0
 public ActionResult Edit([Bind(Include = "Comment_id,Pro_id,Task_id,comment")] Commenttbl commenttbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(commenttbl).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Pro_id  = new SelectList(db.projects, "Pro_id", "Project_Name", commenttbl.Pro_id);
     ViewBag.Task_id = new SelectList(db.task_tables, "Task_id", "Task_Name", commenttbl.Task_id);
     return(View(commenttbl));
 }
示例#28
0
        public IActionResult Put([FromBody] Employee entity)
        {
            var oriEmployee = _dbContext.Employee.SingleOrDefault(c => c.Id == entity.Id);

            if (oriEmployee != null)
            {
                _dbContext.Entry(entity).CurrentValues.SetValues(entity);
                _dbContext.SaveChanges();
                return(Ok());
            }
            return(BadRequest());
        }
示例#29
0
        public int delete(int id)
        {
            human_file us = new human_file();

            //接收前台来的id与表的id匹配
            us.id = id;
            RemoveHoldingEntityInContext(us);
            //开始删除
            db.Entry <human_file>(us).State = EntityState.Deleted;
            //保存
            return(db.SaveChanges());
        }
 public ActionResult Edit([Bind(Include = "AuthorshipID,AuthorID,BookID")] Authorship authorship)
 {
     if (ModelState.IsValid)
     {
         db.Entry(authorship).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "AuthorName", authorship.AuthorID);
     ViewBag.BookID   = new SelectList(db.Books, "BookID", "Title", authorship.BookID);
     return(View(authorship));
 }
        public static void OnContractCompleted(object source, EventArgs e)
        {
            //Not implemented yet - Mark Task as Done
            MyDbContext db = new MyDbContext();

            var contract = (Contract)source;

            var task = db.ContractTasks.Where(t => t.Contract.Id == contract.Id && t.TaskType == TaskTypes.VertragVervollstaendigen).SingleOrDefault();
            task.IsDone = true;

            db.Entry(task).State = EntityState.Modified;
            db.SaveChanges();

            //take care that the task gets removed
            task.TriggerTaskDoneEvent();

            System.Diagnostics.Debug.WriteLine("Vertrag vervollstaendigt");
        }
示例#32
0
        public static void OnDispatcherSet(object source, EventArgs e)
        {
            //Not implemented yet - Mark Task as Done
            MyDbContext db = new MyDbContext();

            var contract = (Contract)source;

            var task = db.ContractTasks.Where(t => t.Contract.Id == contract.Id && t.TaskType == TaskTypes.DispatcherZuweisen).SingleOrDefault();
            task.IsDone = true;

            db.Entry(task).State = EntityState.Modified;
            db.SaveChanges();

            //When the Dispatcher is set, create the tasks for him for completing the contract and uploading the files
            contract.TriggerContractToBeCompletedEvent();
            contract.TriggerFilesToBeAddedEvent();

            //take care that the task gets removed
            task.TriggerTaskDoneEvent();

            System.Diagnostics.Debug.WriteLine("Dispatcher gewaehlt");
        }