コード例 #1
0
        public void Create(Update update)
        {
            // HACK: should be using database-side value generation?
            update.Created = DateTime.UtcNow;

            using (var trans = Session.BeginTransaction())
            {
                Session.Save(update);
                trans.Commit();
            }
        }
コード例 #2
0
        public ActionResult Submit(long id, FormCollection form)
        {
            var destinationUrl = form["DestinationUrl"];
            var wordCount = int.Parse(form["WordCount"]);
            var version = form["Version"];

            // HACK: CheckBox has a subtle behavior in ASP.NET MVC
            //var isUpdateComplete = form["IsUpdateComplete"].Contains("true");

            var mapping = Mappings.Edit(id);

            if (wordCount < 0 && wordCount <= 10000)
            {
                ModelState.AddModelError("WordCount", "Word count should between 0 and 10000.", wordCount.ToString());
            }

            if (string.IsNullOrEmpty(version))
            {
                ModelState.AddModelError("Version", "Version is required.", "");
            }

            if(!string.IsNullOrEmpty((destinationUrl)))
            {
                mapping.DestinationUrl = destinationUrl;
            }
            else
            {
                if(string.IsNullOrEmpty(mapping.DestinationUrl))
                {
                    ModelState.AddModelError("DestinationUrl", "Destination Url is required.", "");
                }
            }

            if(!ModelState.IsValid)
            {
                return View("Update", Mappings.Edit(id));
            }

            var user = Users.Get(User.Identity.Name);

            var update = new Update
            {
                User = user,
                WordCount = wordCount,
                Version = version,
                Mapping = mapping
            };

            mapping.Updates.Add(update);

            Updates.Create(update);

            mapping.Version = version;
            mapping.LastUpdated = DateTime.UtcNow;
            Mappings.Update(mapping);

            ViewData["Message"] = "Update recorded";
            return View("Update", Mappings.Edit(id));
        }