コード例 #1
0
 public ActionResult Edit([Bind(Include = "TeamId,Name")] EditTeamViewModel model)
 {
     if (ModelState.IsValid)
     {
         Team team = db.Teams.Find(model.TeamId);
         if (team != null)
         {
             team.Name = model.Name;
             try
             {
                 db.Entry(team).State = EntityState.Modified;
                 db.SaveChanges();
             }
             catch (Exception ex)
             {
                 return(View("Error", new HandleErrorInfo(ex, "Teams", "Index")));
             }
             return(RedirectToAction("Index"));
         }
         else
         {
             Exception ex = new Exception("Unable to Retrieve Team");
             return(View("Error", new HandleErrorInfo(ex, "Teams", "Index")));
         }
     }
     // Something failed, return model to view
     return(View(model));
 }
コード例 #2
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate")] Side side)
        {
            if (ModelState.IsValid)
            {
                db.Entry(side).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(side));
        }
コード例 #3
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Email,Phone,Fax,WebSite,Address,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Entry(customer).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(customer));
        }
コード例 #4
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] ApplicationUser applicationUser)
        {
            if (ModelState.IsValid)
            {
                db.Entry(applicationUser).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(applicationUser));
        }
コード例 #5
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Description,Extension,FilePath,FileSize,Year,Month,ContentType,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate")] Media media)
        {
            if (ModelState.IsValid)
            {
                db.Entry(media).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(media));
        }
コード例 #6
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,FirstName,LastName,Email,Phone,CreatedBy,CreateDate,UpdatedBy,UpdateDate")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                contact.UpdateDate      = DateTime.Now;
                contact.UpdatedBy       = User.Identity.Name;
                db.Entry(contact).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(contact));
        }
コード例 #7
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,CreatedBy,CreateDate,UpdatedBy,UpdateDate")] Department department)
        {
            if (ModelState.IsValid)
            {
                department.UpdatedBy       = User.Identity.Name;
                department.UpdateDate      = DateTime.Now;
                db.Entry(department).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(department));
        }
コード例 #8
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Title,Description,Status,CategoryId,Attachment,DepartmentId,SideId,CustomerId,ManagerId,OrganizatorId,MeetingDate,MeetingHour,PlannedDate,PlannedHour,FinishDate,FinishHour,ReviseDate,ReviseHour,ConversationSubject,SupporterCompany,SupporterDoctor,ConversationAttendeeCount,ScheduledOrganizationDate,ScheduledOrganizationHour,MailingSubjects,PosterSubject,PosterCount,Elearning,TypesOfScans,AsoCountInScans,TypesOfOrganization,AsoCountInOrganization,TypesOfVaccinationOrganization,AsoCountInVaccinationOrganization,AmountOfCompensantionForPoster,CorporateProductivityReport,CreatedBy,CreateDate,UpdatedBy,UpdateDate")] ToDoItem toDoItem)
        {
            if (ModelState.IsValid)
            {
                toDoItem.UpdateDate      = DateTime.Now;
                toDoItem.UpdatedBy       = User.Identity.Name;
                db.Entry(toDoItem).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryId    = new SelectList(db.Categories, "Id", "Name", toDoItem.CategoryId);
            ViewBag.CustomerId    = new SelectList(db.Customers, "Id", "Name", toDoItem.CustomerId);
            ViewBag.DepartmentId  = new SelectList(db.Departments, "Id", "Name", toDoItem.DepartmentId);
            ViewBag.ManagerId     = new SelectList(db.Contacts, "Id", "FirstName", toDoItem.ManagerId);
            ViewBag.OrganizatorId = new SelectList(db.Contacts, "Id", "FirstName", toDoItem.OrganizatorId);
            ViewBag.SideId        = new SelectList(db.Sides, "Id", "Name", toDoItem.SideId);
            return(View(toDoItem));
        }
コード例 #9
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Description,Extension,FilePath,FileSize,Year,Month,ContentType,CreatedBy,CreateDate,UpdatedBy,UpdateDate")] Media media)
        {
            if (ModelState.IsValid)
            {
                media.UpdateDate = DateTime.Now;
                media.UpdatedBy  = User.Identity.Name;

                //upload işlemi
                if (!String.IsNullOrEmpty(media.FilePath))
                {
                    FileInfo fileInfo = new FileInfo(Server.MapPath("~" + media.FilePath));
                    media.FileSize    = ((float)fileInfo.Length) / 1024;
                    media.Extension   = fileInfo.Extension;
                    media.ContentType = fileInfo.Extension;
                }
                db.Entry(media).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(media));
        }
コード例 #10
0
        public ActionResult Edit([Bind(Include = "PlayerId, Name, TeamIds")] EditPlayerViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Retrieve player from db and perform null check
                Player player = db.Players.Find(Guid.Parse(model.PlayerId));
                if (player == null)
                {
                    return(HttpNotFound());
                }
                // Edit user name per the viewmodel
                player.Name = model.Name;

                // Check if any teams were selected by the user in the form
                if (model.TeamIds.Count > 0)
                {
                    // First, we will instantiate a list to store each of the teams in the EditPlayerViewModel for later comparison
                    List <Team> viewModelTeams = new List <Team>();

                    // Now, loop over each of the ids in the list of TeamIds
                    foreach (var id in model.TeamIds)
                    {
                        // Retrive the team from the db
                        var team = db.Teams.Find(Guid.Parse(id));

                        if (team != null)
                        {
                            // We will add the team to our tracking list of viewmodelteams and player teams
                            try
                            {
                                player.Teams.Add(team);
                                viewModelTeams.Add(team);
                            }
                            catch (Exception ex)
                            {
                                return(View("Error", new HandleErrorInfo(ex, "Players", "Index")));
                            }
                        }
                    }
                    // Now we will create a list of all teams in the db, which we will "Except" from the new player's list
                    var allTeams = db.Teams.ToList();
                    // Now exclude the viewModelTeams from the allTeams list to create a list of teams that we need to delete from the player
                    var teamsToRemove = allTeams.Except(viewModelTeams);
                    // Loop over each of the teams in our teamsToRemove List
                    foreach (var team in teamsToRemove)
                    {
                        try
                        {
                            // Remove that team from the player's Teams list
                            player.Teams.Remove(team);
                        }
                        catch (Exception ex)
                        {
                            // Catch any exceptions and error out
                            return(View("Error", new HandleErrorInfo(ex, "Players", "Index")));
                        }
                    }
                }
                // Save the changes to the db
                try
                {
                    db.Entry(player).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(View("Error", new HandleErrorInfo(ex, "Players", "Indes")));
                }
                // If successfull redirect to player Details
                return(RedirectToAction("Details", new { id = player.PlayerId }));
            }
            // Else something failed, return
            return(View(model));
        }