Ejemplo n.º 1
0
        public ActionResult UpdateCard(CardModel model)
        {
            Card card = new Card
            {
                c_ID = model.cID,
                c_DayID = model.DayId,
                c_Index = model.Index,
                c_Name = model.Name,
                c_Minutes = model.Minutes,
                c_StartHour = model.StartHour,
                c_FixedHour = model.Fixed,
                c_Done = model.Done
            };
            repositoryCard.UpdateCard(card);

            //sa updatez indecsii pt ca nu ii corectez altfel
            List<Card> lstCards = repositoryCard.Cards
                    .Where(c => c.c_DayID == model.DayId)
                    .OrderBy(c => c.c_StartHour)
                    .ToList();
            for(int i = 0; i < lstCards.Count; i++)
            {
                lstCards[i].c_Index = i;
                repositoryCard.UpdateCard(lstCards[i]);
            }


            return RedirectToAction("ListDays", "Day");
        }
Ejemplo n.º 2
0
        public ActionResult AddCard(CardModel model)
        {
            Day day = repositoryDay.Days.First(d => d.d_ID == model.DayId);
            DateTime genericDate = 
                new DateTime(2015, day.d_Date.Month, day.d_Date.Day, 0, 0, 0);

            DateTime previousEndHour = new DateTime();
            List<Card> lstCardsAfter = new List<Card>();
            if (model.StartHour != genericDate)//pun dupa ora
            {
                //gaseste primul card cu ora mai mare ca el
                lstCardsAfter = repositoryCard.Cards
                    .Where(c => c.c_DayID == model.DayId)
                    .Where(c => c.c_StartHour >= model.StartHour)
                    .OrderBy(c => c.c_StartHour)
                    .ToList();

                previousEndHour =
                    model.StartHour.AddMinutes(model.Minutes);

            }
            else if (model.Index != 0)//pun dupa index
            {
                //gaseste primul card cu index mai mare ca el
                lstCardsAfter = repositoryCard.Cards
                    .Where(c => c.c_DayID == model.DayId)
                    .Where(c => c.c_Index >= model.Index)
                    .OrderBy(c => c.c_StartHour)
                    .ToList();

                //gaseste primul card cu index mai mic ca el
                Card cardBefore = repositoryCard.Cards
                    .Where(c => c.c_DayID == model.DayId)
                    .Where(c => c.c_Index < model.Index)
                    .OrderByDescending(c => c.c_StartHour)
                    .First();

                model.StartHour = 
                    cardBefore.c_StartHour.AddMinutes(cardBefore.c_Minutes);

                previousEndHour = model.StartHour.AddMinutes(model.Minutes);
            }

            if (lstCardsAfter.Count > 0)
            {
                model.Index = lstCardsAfter.First().c_Index;

                // la toate cardurile de mai tarziu schimba-le indexul si ora
                int currentIndex = model.Index + 1;

                foreach (Card cardAfter in lstCardsAfter)
                {
                    cardAfter.c_Index = currentIndex;

                    if (cardAfter.c_FixedHour == false) // care nu sunt fixe
                    {
                        if (previousEndHour >= cardAfter.c_StartHour)
                        {
                            cardAfter.c_StartHour = previousEndHour;
                        }
                        previousEndHour =
                            cardAfter.c_StartHour.AddMinutes(cardAfter.c_Minutes);
                    }

                    repositoryCard.SaveCard(cardAfter);

                    currentIndex = currentIndex + 1;
                }
            }
            else
            {
                //daca pun un index f mare
                if (model.Index > repositoryCard.Cards
                    .Count(c => c.c_DayID == model.DayId)+1)
                {
                    model.Index = repositoryCard.Cards
                        .Count(c => c.c_DayID == model.DayId);
                }
            }

            //in ce situatie nu adaug ?
            repositoryCard.SaveCard(new Card
            {
                c_DayID = model.DayId,
                c_Name = model.Name,
                c_Minutes = model.Minutes,
                c_StartHour = model.StartHour,
                c_Index = model.Index
            });

            return RedirectToAction("ListDays", "Day");
        }
Ejemplo n.º 3
0
        public ViewResult UpdateCard(int id)
        {
            Card card = repositoryCard.Cards.First(c => c.c_ID == id);
            CardModel model = new CardModel
            {
                cID = card.c_ID,
                DayId = card.c_DayID,
                Index = card.c_Index,
                Name = card.c_Name,
                Minutes = card.c_Minutes,
                StartHour = card.c_StartHour,
                Fixed = card.c_FixedHour,
                Done = card.c_Done
            };

            return View(model);
        }
Ejemplo n.º 4
0
        public ViewResult AddCard(int id)
        {
            Day day = repositoryDay.Days.First(d => d.d_ID == id);

            CardModel model = new CardModel
            {
                DayId = id,
                StartHour = new DateTime(2015, day.d_Date.Month,day.d_Date.Day)
            };

            return View(model);
        }