Пример #1
0
        public ActionResult _DeleteConfirmed(int id)
        {
            CImage image       = context.FindPhotoById(id);
            var    myImageType = image.type;

            context.Delete <CImage>(image);
            context.SaveChanges();

            var myImageLibModel = GetLatestImageLibrary(myImageType);

            return(PartialView("_ImageLibrary", myImageLibModel));
        }
        public ActionResult _EventCreateInstance(int evtId, string evtDate)
        {
            var query = from evt in context.CEvents
                        where evt.id == evtId
                        select evt;
            //clone the event
            CEvent myEvent       = query.First();
            CEvent myClonedEvent = myEvent.DeepCopy();

            //set the recurring to false
            myClonedEvent.Recurring      = false;
            myClonedEvent.recurranceType = (int)Recurrance.None;
            //the existence of this ref will also hide recurrance options from the form
            myClonedEvent.recurranceRef = myEvent.id;

            myClonedEvent.EventDate = DateTime.Parse(evtDate);
            //reset the start and end datetime values

            string myNewStartDate = myClonedEvent.EventDate.ToShortDateString() + " " + DateTime.Parse(myEvent.start.ToString()).ToShortTimeString();

            myClonedEvent.start = DateTime.Parse(myNewStartDate);

            string myNewEndDate = myClonedEvent.EventDate.ToShortDateString() + " " + DateTime.Parse(myEvent.end.ToString()).ToShortTimeString();

            myClonedEvent.end = DateTime.Parse(myNewEndDate);

            myClonedEvent.id = context.CEvents.OrderByDescending(evt => evt.id).FirstOrDefault().id + 1;

            int myNewEventId;

            try
            {
                context.Add <CEvent>(myClonedEvent);
                myNewEventId = context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                        ModelState.AddModelError(ve.PropertyName, ve.ErrorMessage);
                    }
                }
            }

            return(PartialView("_EventDialogue", myClonedEvent));
        }