Beispiel #1
0
 public ActionResult Edit(int id, FormCollection formCollection)
 {
     using (var dataContext = new DataContext())
     {
         var card = dataContext.Cards.Find(id);
         if (ModelState.IsValid)
         {
             try
             {
                 UpdateModel(card);
                 dataContext.SaveChanges();
                 return PartialView(card);
             }
             catch
             {
                 return Content("something horrible happened. Sorry about that. Best to just move on.");
             }
         }
         return PartialView(card);
     }
 }
Beispiel #2
0
        public ActionResult UpdateCardAttribute(int cardId, string attributeKey, string attributeValue)
        {
            using(var dataContext = new DataContext())
            {
                var attribute = dataContext.Cards
                    .Where(c => c.Id == cardId)
                    .SelectMany(c => c.Attributes)
                    .Where(a => a.Key == attributeKey)
                    .FirstOrDefault();

                if(attribute == null)
                    return new HttpStatusCodeResult(HttpStatusCode.NotFound);

                attribute.Value = attributeValue;
                dataContext.SaveChanges();
                return new HttpStatusCodeResult(HttpStatusCode.OK);
            }
        }
Beispiel #3
0
        public ActionResult UpdateCardDisplayOrder(int cardId, int? previousCardId, string attributeKey)
        {
            using(var dataContext = new DataContext())
            {
                var attribute = dataContext.Cards
                    .Where(c => c.Id == cardId)
                    .SelectMany(c => c.Attributes)
                    .Where(a => a.Key == attributeKey)
                    .FirstOrDefault();

                if(attribute == null)
                    return new HttpStatusCodeResult(HttpStatusCode.NotFound);

                var previousAttributeDisplayIndex = dataContext.Cards
                    .Where(c => c.Id == previousCardId)
                    .SelectMany(c => c.Attributes)
                    .Where(a => a.Key == attributeKey)
                    .Select(a => a.DisplayOrder)
                    .DefaultIfEmpty(-1)
                    .FirstOrDefault();

                attribute.DisplayOrder = previousAttributeDisplayIndex + 1;

                foreach(var followingAttribute in dataContext.Attributes
                    .Where(a => a.Key == attributeKey)
                    .Where(a => a.DisplayOrder > previousAttributeDisplayIndex))
                {
                    followingAttribute.DisplayOrder += 1;
                }

                dataContext.SaveChanges();
                return new HttpStatusCodeResult(HttpStatusCode.OK);
            }
        }