public ActionResult Edit(int id, FormCollection collection, string Upload)
        {
            var announcement = _entities.Announcements.Single(a => a.ID == id);

            try
            {
                ImageController   ac          = new ImageController();
                List <UploadFile> uploadFiles = ac.GenerateAttachFileCollectionID(collection, "Announcement");

                if (Upload != null)
                {
                    ImageUploadToServer();

                    if (uploadFiles != null)
                    {
                        ModelStateSetting(uploadFiles, "Announcement");
                    }

                    UpdateModel(announcement, "Announcement");
                    var viewModel = new AnnouncementViewModel()
                    {
                        Announcement = announcement,
                    };
                    return(View(viewModel));
                }

                List <AnnouncementUploadFile> aUploadFiles = announcement.AnnouncementUploadFiles.ToList();
                foreach (AnnouncementUploadFile aUploadFile in aUploadFiles)
                {
                    announcement.AnnouncementUploadFiles.Remove(aUploadFile);
                }

                foreach (UploadFile uploadFile in uploadFiles)
                {
                    AnnouncementUploadFile auf = new AnnouncementUploadFile();
                    auf.UploadFileID = uploadFile.ID;
                    announcement.AnnouncementUploadFiles.Add(auf);
                }

                announcement.AnnounceDate = DateTime.Parse(collection.GetValues("Announcement.AnnounceDate")[0]);
                announcement.Description  = collection.GetValues("Announcement.Description")[0];
                announcement.IsPublic     = bool.Parse(collection.GetValues("Announcement.IsPublic")[0]);
                announcement.Name         = collection.GetValues("Announcement.Name")[0];
                announcement.StaticURL    = collection.GetValues("Announcement.StaticURL")[0];
                //announcement. = collection.Get("Announcement.URLChecked");

                //UpdateModel(announcement, "Announcement");
                _entities.SaveChanges();

                return(RedirectToAction("Index", new { announceGroupID = announcement.AnnounceGroupID }));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(FormCollection collection, Announcement announcement, string Upload)
        {
            MembershipUser mu = Membership.GetUser();

            try
            {
                ImageController   ac          = new ImageController();
                List <UploadFile> uploadFiles = ac.GenerateAttachFileCollectionID(collection, "Announcement");

                if (Upload != null)
                {
                    ImageUploadToServer();
                    if (uploadFiles != null)
                    {
                        ModelStateSetting(uploadFiles, "Announcement");
                    }
                    var viewModel = new AnnouncementViewModel
                    {
                        Announcement    = announcement,
                        AnnouncementIDs = new List <int>(),
                    };
                    viewModel.AnnouncementIDs.Add((int)TempData["AnnounceGroupID"]);
                    return(View(viewModel));
                }

                foreach (UploadFile uploadFile in uploadFiles)
                {
                    AnnouncementUploadFile auf = new AnnouncementUploadFile();
                    auf.UploadFileID = uploadFile.ID;
                    announcement.AnnouncementUploadFiles.Add(auf);
                }

                announcement.AnnouncerID     = (Guid)(mu.ProviderUserKey);
                announcement.AnnounceGroupID = (int)TempData["AnnounceGroupID"];

                _entities.AddToAnnouncements(announcement);
                _entities.SaveChanges();

                return(RedirectToAction("Index", new { announceGroupID = (int)TempData["AnnounceGroupID"] }));
            }
            catch
            {
                return(View());
            }
        }