示例#1
0
        private ActionResult PerformDownload(Version version)
        {
            string pfn = Server.MapPath("~/" + version.Filename);

            if (!System.IO.File.Exists(pfn))
            {
                //throw new ArgumentException("Invalid file name or file not exists!");

                return(HandleError404());
            }
            var download = new Download
            {
                DlDate = DateTime.Now,
                CmId   = _db.Users.Single(u => u.EMail == User.Identity.Name).UId,
                VrId   = version.VrId
            };

            _db.AddToDownloads(download);
            _db.SaveChanges();
            return(new BinaryContentResult
            {
                FileName = Path.GetFileName(@pfn),
                ContentType = "application/octet-stream",
                Content = System.IO.File.ReadAllBytes(pfn)
            });
        }
示例#2
0
        public NewVersionEmailTemplate(User user, Module module, Version version)
            : base("Services/EmailTemplates/NewVersionEmailTemplate.html")
        {
            Fields = new Dictionary <string, string>(
                StringComparer.OrdinalIgnoreCase)
            {
                { "username", user.NickName },
                { "date", DateTime.Now.ToString("d", CultureInfo.CreateSpecificCulture("de-DE")) },
                { "modulename", module.Name },
                { "newversion", version.Release.ToString() }
            };

            ReadTemplate();
        }
        public void Edit()
        {
            ModuleController controller = new ModuleController();
            int id = 0;

            VersionR.Models.Version model = new VersionR.Models.Version();

            RedirectToRouteResult result = (RedirectToRouteResult)controller.Edit(id);

            Assert.AreEqual("List", result.RouteValues["action"]);

            result = (RedirectToRouteResult)controller.Edit(id, model);

            Assert.AreEqual("List", result.RouteValues["action"]);
        }
示例#4
0
 public ActionResult Edit(int id, Version model)
 {
     try
     {
         var module = _db.Modules.Single(m => m.ModId == id);
         if (ModelState.IsValid)
         {
             UpdateModel(module);
             _db.SaveChanges();
             return(RedirectToAction("Details", new { id }));
         }
         return(View(module));
     }
     catch (Exception)
     {
         return(RedirectToAction("List"));
     }
 }
示例#5
0
        public ActionResult Delete(int id, Version model)
        {
            try
            {
                var toDelete = _repos.VersionRepository.GetByID(id); //_db.Versions.Single(v => v.VrId == id);

                var deletePath = Path.Combine(HttpContext.Server.MapPath("~/"),
                                              toDelete.Filename);

                _repos.VersionRepository.Delete(toDelete, deletePath);
                TempData["uihint"] = new UiHint("Erfolg!",
                                                "Die Version wurde erfolgriech gelöscht!",
                                                new { @class = "alert alert-success" });
                _repos.Save();

                return(RedirectToAction("Details", "Module", new { id = toDelete.ModId }));
            }
            catch (Exception)
            {
                return(HandleError404());
            }
        }
示例#6
0
        //
        // GET: /Admin/Version/Create
        public ActionResult Add(int id)
        {
            var currentUser   = _db.Users.Single(u => u.EMail == User.Identity.Name);
            var currentModule = _db.Modules.Single(m => m.ModId == id);

            var model = new Version();

            model.EmId   = currentUser.UId;
            model.User   = currentUser;
            model.ModId  = id;
            model.Module = currentModule;

            try
            {
                var lastVersion =
                    currentModule.Versions.OrderByDescending(v => v.Release + v.SubRelease + v.BuildId).First();
                model.Release    = lastVersion.Release;
                model.SubRelease = lastVersion.SubRelease;
                model.BuildId    = lastVersion.BuildId;
            }
            catch (Exception)
            {
                model.Release    = 0;
                model.SubRelease = 0;
                model.BuildId    = "1";
            }

            model.ReleaseDate = DateTime.Now;

            var viewModel = new VersionViewModel
            {
                Version     = model,
                ReleaseDate =
                    model.ReleaseDate.ToString("d", CultureInfo.CreateSpecificCulture("de-DE"))
            };

            return(View(viewModel));
        }
示例#7
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // Optional: Work only for authenticated users
            if (!filterContext.RequestContext.HttpContext.User.Identity.IsAuthenticated)
            {
                return;
            }

            // Optional: Work only for GET request
            if (filterContext.RequestContext.HttpContext.Request.RequestType != "GET")
            {
                return;
            }

            // Optional: Do not work with AjaxRequests
            if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
            {
                return;
            }

            var currentUser =
                _db.Users.Single(
                    u => u.EMail == filterContext.RequestContext.HttpContext.User.Identity.Name);

            var downloadRepository = _repos.DownloadRepository;
            var moduleRepository   = _repos.ModuleRepository;

            var notificationList = new List <UserNotification>();

            foreach (var customerModule in currentUser.Customer_Modules)
            {
                try
                {
                    var currentModule = customerModule.Module;
                    var latestVersion = currentModule.GetLatestVersion();
                    var userVersion   = new Version();

                    var userModuleDownloads = currentUser.Downloads.Where(d => d.Version.Module == currentModule)
                                              .OrderByDescending(
                        du => du.Version.Release + du.Version.SubRelease + du.Version.BuildId);

                    if (userModuleDownloads.Any())
                    {
                        userVersion = userModuleDownloads.First().Version;
                    }

                    if (latestVersion.IsGreater(userVersion))
                    {
                        notificationList.Add(new UserNotification(new NewVersionNotificationType(),
                                                                  "Die Version " +
                                                                  latestVersion.Release + "." + latestVersion.SubRelease +
                                                                  "." + latestVersion.BuildId
                                                                  + " von " + latestVersion.Module.Name +
                                                                  " ist verfügbar!",
                                                                  latestVersion.VrId));
                    }
                }
                catch (InvalidOperationException e)
                {
                    Console.Out.Write(e.Message);
                }
            }

            filterContext.Controller.TempData["UserNotification"] = notificationList;
            //throw new Exception(notificationList.Count.ToString());
        }