Exemple #1
0
 public VMContributionMedium(ContributionMedium medium)//ContributionMedium medium)
 {
     Link      = medium.Link;
     MediaType = (MediaType)medium.MediumType;
     Caption   = medium.Caption;
     Id        = medium.Id;
     UserId    = medium.UserId;
     ProjectId = medium.ProjectId;
 }
 //ContributionMedium medium)
 public VMContributionMedium(ContributionMedium medium)
 {
     Link = medium.Link;
     MediaType = (MediaType)medium.MediumType;
     Caption = medium.Caption;
     Id = medium.Id;
     UserId = medium.UserId;
     ProjectId = medium.ProjectId;
 }
Exemple #3
0
 public void addContributionMedium(ContributionMedium m, int userId, int projectId)
 {
     using (var db = new PortfolioUnleashedContext())
     {
         m.UserId    = userId;    //in case they didn't set this (not auto set by db)
         m.ProjectId = projectId; //in case they didn't set this (not auto set by db)
         db.Contributions.Include("ContributionMedia").Include("Project").Include("User").FirstOrDefault(c => c.UserId == userId && c.ProjectId == projectId).ContributionMedia.Add(m);
         db.SaveChanges();
     }
 }
 public void addContributionMedium(ContributionMedium m, int userId, int projectId)
 {
     using (var db = new PortfolioUnleashedContext())
     {
         m.UserId = userId;//in case they didn't set this (not auto set by db)
         m.ProjectId = projectId;//in case they didn't set this (not auto set by db)
         db.Contributions.Include("ContributionMedia").Include("Project").Include("User").FirstOrDefault(c => c.UserId == userId && c.ProjectId == projectId).ContributionMedia.Add(m);
         db.SaveChanges();
     }
 }
Exemple #5
0
 public void removeContributionMedium(ContributionMedium m)
 {
     using (var db = new PortfolioUnleashedContext())
     {
         if (db.Contributions.Include("ContributionMedia").Any(c => c.ContributionMedia.Any(me => me.Id == m.Id)))                                                                                    //if any contribution has this contribution medium
         {
             foreach (Contribution c in db.Contributions.Include("ContributionMedia").Where(c => c.ContributionMedia.Any(me => me.Id == m.Id)))                                                       //for each contribution that has this contribution medium
             {
                 db.Contributions.Include("ContributionMedia").FirstOrDefault(co => co.UserId == c.UserId).ContributionMedia.Remove(c.ContributionMedia.Where(me => me.Id == m.Id).FirstOrDefault()); //remove that medium
             }
         }
         db.ContributionMediums.Remove(db.ContributionMediums.Where(me => me.Id == m.Id).FirstOrDefault());//remove the contribution medium from table
         db.SaveChanges();
     }
 }
Exemple #6
0
        public static List <ContributionMedium> contributionMediumListFromVMContributionMediumList(List <VMContributionMedium> vmMedias)
        {
            List <ContributionMedium> mediums = new List <ContributionMedium>();

            foreach (VMContributionMedium vmMedium in vmMedias)
            {
                ContributionMedium medium = new ContributionMedium()
                {
                    Link       = vmMedium.Link,
                    MediumType = (int)vmMedium.MediaType,
                    Caption    = vmMedium.Caption,
                    UserId     = vmMedium.UserId,
                    ProjectId  = vmMedium.ProjectId,
                    Id         = vmMedium.Id,
                };
                mediums.Add(medium);
            }
            return(mediums);
        }
Exemple #7
0
 public void updateContributionMedium(ContributionMedium m)
 {
     using (var db = new PortfolioUnleashedContext())
     {
         if (m.Link != null)
         {
             db.ContributionMediums.FirstOrDefault(med => med.Id == m.Id).Link = m.Link;
         }
         if (m.MediumType != db.ContributionMediums.FirstOrDefault(med => med.Id == m.Id).MediumType)
         {
             db.ProjectMediums.FirstOrDefault(med => med.Id == m.Id).MediumType = m.MediumType;
         }
         if (m.Caption != null)
         {
             db.ContributionMediums.FirstOrDefault(med => med.Id == m.Id).Caption = m.Caption;
         }
         db.SaveChanges();
     }
 }
        public static List<ContributionMedium> contributionMediumListFromVMContributionMediumList(List<VMContributionMedium> vmMedias)
        {
            List<ContributionMedium> mediums = new List<ContributionMedium>();
            foreach (VMContributionMedium vmMedium in vmMedias)
            {
                ContributionMedium medium = new ContributionMedium()
                {
                    Link = vmMedium.Link,
                    MediumType = (int)vmMedium.MediaType,
                    Caption = vmMedium.Caption,
                    UserId = vmMedium.UserId,
                    ProjectId = vmMedium.ProjectId,
                    Id = vmMedium.Id,

                };
                mediums.Add(medium);
            }
            return mediums;
        }
 public void updateContributionMedium(ContributionMedium m)
 {
     using (var db = new PortfolioUnleashedContext())
     {
         if (m.Link != null) db.ContributionMediums.FirstOrDefault(med => med.Id == m.Id).Link = m.Link;
         if (m.MediumType != db.ContributionMediums.FirstOrDefault(med => med.Id == m.Id).MediumType) db.ProjectMediums.FirstOrDefault(med => med.Id == m.Id).MediumType = m.MediumType;
         if (m.Caption != null) db.ContributionMediums.FirstOrDefault(med => med.Id == m.Id).Caption = m.Caption;
         db.SaveChanges();
     }
 }
 public void removeContributionMedium(ContributionMedium m)
 {
     using (var db = new PortfolioUnleashedContext())
     {
         if (db.Contributions.Include("ContributionMedia").Any(c => c.ContributionMedia.Any(me => me.Id == m.Id)))//if any contribution has this contribution medium
         {
             foreach (Contribution c in db.Contributions.Include("ContributionMedia").Where(c => c.ContributionMedia.Any(me => me.Id == m.Id)))//for each contribution that has this contribution medium
             {
                 db.Contributions.Include("ContributionMedia").FirstOrDefault(co => co.UserId == c.UserId).ContributionMedia.Remove(c.ContributionMedia.Where(me => me.Id == m.Id).FirstOrDefault());//remove that medium
             }
         }
         db.ContributionMediums.Remove(db.ContributionMediums.Where(me => me.Id == m.Id).FirstOrDefault());//remove the contribution medium from table
         db.SaveChanges();
     }
 }
 private bool AllContributionMediaVerified(out List<ContributionMedium> media)
 {
     bool isValidInput = true;
     media = new List<ContributionMedium>();
     string[] mediaIds = Request.Form.GetValues("ContributionMedia.Id");
     string[] mediaLinks = Request.Form.GetValues("ContributionMedia.Link");
     string[] mediaMediaTypes = Request.Form.GetValues("ContributionMedia.MediaType");
     string[] mediaCaptions = Request.Form.GetValues("ContributionMedia.Caption");
     for (int i = 0; i < mediaIds.Count(); i++)
     {
         string[] entryInputs = new string[] { mediaIds[i], mediaLinks[i], mediaCaptions[i] };
         if (!allAreNullOrEmpty(entryInputs))
         {
             entryInputs = new string[] { mediaLinks[i], mediaCaptions[i] };
             if (someAreNullOrEmpty(entryInputs))
             {
                 isValidInput = false;
                 ModelState.AddModelError("", "If you add a Media entry to your contribution, you must either complete all fields for that entry or leave all fields blank.");
             }
             else
             {
                 int specifiedMediaType = (int)((MediaType)Enum.Parse(typeof(MediaType), mediaMediaTypes[i]));
                 isValidInput = verifyMediaTypeMatchesMedia(specifiedMediaType, mediaLinks[i]);
             }
             ContributionMedium medium = new ContributionMedium();
             medium.Caption = mediaCaptions[i];
             medium.Link = mediaLinks[i];
             medium.Id = int.Parse(mediaIds[i]);
             medium.MediumType = (int)((MediaType)Enum.Parse(typeof(MediaType), mediaMediaTypes[i]));
             medium.UserId = WebSecurity.CurrentUserId;
             media.Add(medium);
         }
     }
     return isValidInput;
 }