コード例 #1
0
      private void UpdateMemberPositions(string[] selectedPositions, Member memberToUpdate)
      {
          if (selectedPositions == null)
          {
              memberToUpdate.MemberPositions = new List <MemberPosition>();
              return;
          }

          var selectedPositionsHS = new HashSet <string>(selectedPositions);
          var memberPos           = new HashSet <int>
                                        (memberToUpdate.MemberPositions.Select(p => p.PositionID));//IDs of the currently selected conditions

          foreach (var pos in _context.Positions)
          {
              if (selectedPositionsHS.Contains(pos.ID.ToString()))
              {
                  if (!memberPos.Contains(pos.ID))
                  {
                      memberToUpdate.MemberPositions.Add(new MemberPosition {
                            MemberID = memberToUpdate.ID, PositionID = pos.ID
                        });
                  }
              }
              else
              {
                  if (memberPos.Contains(pos.ID))
                  {
                      MemberPosition positionToRemove = memberToUpdate.MemberPositions.SingleOrDefault(c => c.PositionID == pos.ID);
                      _context.Remove(positionToRemove);
                  }
              }
          }
      }
コード例 #2
0
 public MemberInfo()
 {
     Name       = Email = Birthday = Address = string.Empty;
     Position   = MemberPosition.Employee;
     Location   = Point.Empty;
     SubMembers = new List <MemberInfo>();
 }
コード例 #3
0
      public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Phone,eMail,AssignmentID")] Member member, string[] selectedPositions, IFormFile thePicture)
      {
          try
          {
              if (selectedPositions != null)
              {
                  member.MemberPositions = new List <MemberPosition>();
                  foreach (var pos in selectedPositions)
                  {
                      var posToAdd = new MemberPosition {
                          MemberID = member.ID, PositionID = int.Parse(pos)
                      };
                      member.MemberPositions.Add(posToAdd);
                  }
              }

              if (ModelState.IsValid)
              {
                  if (thePicture != null)
                  {
                      string mimeType   = thePicture.ContentType;
                      long   fileLength = thePicture.Length;
                      if (!(mimeType == "" || fileLength == 0))  //Looks like we have a file!!!
                      {
                          if (mimeType.Contains("image"))
                          {
                              using (var memoryStream = new MemoryStream())
                              {
                                  await thePicture.CopyToAsync(memoryStream);

                                  member.imageContent = memoryStream.ToArray();
                              }
                              member.imageMimeType = mimeType;
                              member.imageFileName = thePicture.FileName;
                          }
                      }
                  }
                  _context.Add(member);
                  await _context.SaveChangesAsync();

                  return(RedirectToAction(nameof(Index)));
              }
          }
          catch (RetryLimitExceededException /* dex */)
          {
              ModelState.AddModelError("", "Unable to save changes after multiple attempts. Try again, and if the problem persists, see your system administrator.");
          }
          catch (DataException dex)
          {
              if (dex.InnerException.Message.Contains("IX_Members_eMail"))
              {
                  ModelState.AddModelError("eMail", "Unable to save changes. Remember, you cannot have duplicate Emails.");
              }
              else
              {
                  ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
              }
          }
          catch (Exception)
          {
              ModelState.AddModelError("", "Unable to spit");
          }
          PopulateAssignedPositionData(member);
          PopulateDropDownLists(member);
          return(View(member));
      }
コード例 #4
0
 public bool DeleteMemberPosition(MemberPosition memberPosition)
 {
     unitOfWork.MemberPositionRepository.Delete(memberPosition);
     return(unitOfWork.Save());
 }
コード例 #5
0
 public bool InsertMemberPosition(MemberPosition memberPosition)
 {
     unitOfWork.MemberPositionRepository.Insert(memberPosition);
     return(unitOfWork.Save());
 }