Esempio n. 1
0
        public ActionResult ManageRepresentativeExternalLinks(int repId)
        {
            RepresentativeService   service = new RepresentativeService();
            RepresentativeEditModel model   = service.GetRepresentativeEditModel(repId);

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult DeleteRepresentative(int repId)
        {
            RepresentativeService   service = new RepresentativeService();
            RepresentativeEditModel model   = service.GetRepresentativeEditModel(repId);

            return(View(model));
        }
Esempio n. 3
0
        public ActionResult CreateRepresentative(int parliamentHouseId)
        {
            RepresentativeService   service = new RepresentativeService();
            RepresentativeEditModel model   = service.InitializeRepresentativeModelForCreate(parliamentHouseId);

            return(View(model));
        }
Esempio n. 4
0
        public ActionResult EditRepresentative(RepresentativeEditModel model)
        {
            TryUpdateModel(model);
            RepresentativeService service = new RepresentativeService();

            model = service.UpdateRepresentative(model);
            return(RedirectToAction("RepresentativeDetails", new { repId = model.RepresentativeID }));
        }
Esempio n. 5
0
        public ActionResult CreateRepresentative(RepresentativeEditModel model)
        {
            TryUpdateModel(model);


            RepresentativeService service = new RepresentativeService();
            var representativeId          = service.CreateRepresentative(model);

            return(RedirectToAction("RepresentativeDetails", new { repId = representativeId }));
        }
Esempio n. 6
0
        public int CreateRepresentative(RepresentativeEditModel model)
        {
            if (model == null ||
                model.SelectedPartyID <= 0)
            {
                return(0);
            }

            using (var context = JavnaRasprava.WEB.DomainModels.ApplicationDbContext.Create())
            {
                var party = context.Parties.Where(x => x.PartyID == model.SelectedPartyID).FirstOrDefault();

                if (party == null)
                {
                    return(0);
                }

                var house = context.ParliamentHouses
                            .Where(x => x.ParliamentHouseID == model.ParliamentHouseID)
                            .FirstOrDefault();

                if (house == null)
                {
                    return(0);
                }


                var representative = new Representative
                {
                    FirstName         = model.FirstName,
                    LastName          = model.LastName,
                    Resume            = model.Resume,
                    Email             = model.Email,
                    ParliamentHouseID = model.ParliamentHouseID,
                    PartyID           = model.SelectedPartyID,
                    NumberOfVotes     = model.NumberOfVotes,
                    EletorialUnit     = model.EletorialUnit,
                    Function          = model.Function
                };


                if (model.Image != null)
                {
                    var fileService = new FileService();
                    representative.ImageRelativePath = fileService.UploadFile(new List <string> {
                        "Representatives"
                    }, model.Image.FileName, model.Image.InputStream);
                }

                context.Representatives.Add(representative);
                context.SaveChanges();

                return(representative.RepresentativeID);
            }
        }
Esempio n. 7
0
        public RepresentativeEditModel UpdateRepresentative(RepresentativeEditModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = JavnaRasprava.WEB.DomainModels.ApplicationDbContext.Create())
            {
                var party = context.Parties.Where(x => x.PartyID == model.SelectedPartyID).FirstOrDefault();

                if (party == null)
                {
                    return(null);
                }

                var representative = context.Representatives.Where(x => x.RepresentativeID == model.RepresentativeID).FirstOrDefault();

                if (representative == null)
                {
                    return(null);
                }

                representative.FirstName = model.FirstName;
                representative.LastName  = model.LastName;
                // representative.ImageRelativePath = model.ImageRelativePath;
                representative.Resume  = model.Resume;
                representative.Email   = model.Email;
                representative.PartyID = model.SelectedPartyID;

                representative.NumberOfVotes = model.NumberOfVotes;
                representative.EletorialUnit = model.EletorialUnit;
                representative.Function      = model.Function;

                if (model.Image != null)
                {
                    var fileService = new FileService();
                    representative.ImageRelativePath = fileService.UploadFile(new List <string> {
                        "Representatives"
                    }, model.Image.FileName, model.Image.InputStream);
                }
                else
                {
                    representative.ImageRelativePath = model.ImageRelativePath;
                }

                context.SaveChanges();
            }

            return(GetRepresentativeEditModel(model.RepresentativeID));
        }
Esempio n. 8
0
        public RepresentativeEditModel GetRepresentativeEditModel(int representativeID)
        {
            using (var context = JavnaRasprava.WEB.DomainModels.ApplicationDbContext.Create())
            {
                var rep = context.Representatives
                          .Where(x => x.RepresentativeID == representativeID)
                          .Include(x => x.ExternalLinks)
                          .Include(x => x.ParliamentHouse.Parliament)
                          .Include(x => x.Party)
                          .Include(x => x.Assignments)
                          .FirstOrDefault();

                if (rep == null)
                {
                    return(null);
                }

                RepresentativeEditModel model = InitializeRepresentativeEditModel(context);

                model.RepresentativeID    = rep.RepresentativeID;
                model.FirstName           = rep.FirstName;
                model.LastName            = rep.LastName;
                model.Resume              = rep.Resume;
                model.Email               = rep.Email;
                model.ImageRelativePath   = rep.ImageRelativePath;
                model.SelectedPartyID     = rep.PartyID;
                model.ExternalLinks       = TransformExternalLinks(rep.ExternalLinks);
                model.Assignments         = TransformAssignments(rep.Assignments);
                model.PartyName           = rep.Party.Name;
                model.ParliamentHouseName = rep.ParliamentHouse.Name;
                model.ParliamentName      = rep.ParliamentHouse.Parliament.Name;
                model.NumberOfVotes       = rep.NumberOfVotes;
                model.EletorialUnit       = rep.EletorialUnit;
                model.Function            = rep.Function;

                model.UserRepresentativeQuestions = context.UserRepresentativeQuestions
                                                    .Where(x => x.RepresentativeID == representativeID)
                                                    .Where(x => x.Question.Law == null)
                                                    .Select(x => new JavnaRasprava.WEB.Models.Representative.RepresentativeQuestionModel
                {
                    ID    = x.QuestionID,
                    Title = x.Question.Text
                })
                                                    .ToList();

                return(model);
            }
        }