public NotasCache RemoveFromCache(NotasCache cached, SinglePropJson json)
 {
     if (cached.anchored.Any(nota => nota.NotaId == int.Parse(json.Value)))
     {
         cached.anchored.Remove(cached.anchored.Where(nota => nota.NotaId == int.Parse(json.Value)).First());
     }
     else
     {
         cached.notAnchored.Remove(cached.notAnchored.Where(nota => nota.NotaId == int.Parse(json.Value)).First());
     }
     return(cached);
 }
示例#2
0
        public ActionResult Save(NotaDTO dto)
        {
            PersistedState ps = _notasService.Edit(dto);

            if (ps == PersistedState.OK)
            {
                NotasCache cached = GetSessionItem <NotasCache>(Resources.MisNotas);
                RemoveFromSession(Resources.MisNotas);
                SetSessionItem(Resources.MisNotas, _notasService.UpdateCache(cached, dto));
            }
            return(SimpleJSONFeedback(ps));
        }
示例#3
0
        public ActionResult Delete(SinglePropJson json)
        {
            PersistedState ps = _notasService.Remove(int.Parse(json.Value));

            if (ps == PersistedState.OK)
            {
                NotasCache cached = GetSessionItem <NotasCache>(Resources.MisNotas);
                RemoveFromSession(Resources.MisNotas);
                SetSessionItem(Resources.MisNotas, _notasService.RemoveFromCache(cached, json));
            }

            return(SimpleJSONFeedback(ps));
        }
示例#4
0
        public async Task <ActionResult> Create(CreateNotaDTO dto)
        {
            var tuple = await Task.Run(() => _notasService.Create(dto, GetCurrentUser()));

            if (tuple.Item1 == PersistedState.OK && ExistsKey(Resources.MisNotas))
            {
                NotasCache cached = GetSessionItem <NotasCache>(Resources.MisNotas);
                if (dto.Anchor)
                {
                    cached.anchored.Add(tuple.Item2);
                    cached.anchored = cached.anchored.OrderByDescending(nota => nota.CDT).ToList();
                }
                else
                {
                    cached.notAnchored.Add(tuple.Item2);
                    cached.notAnchored = cached.notAnchored.OrderByDescending(nota => nota.CDT).ToList();
                }
                RemoveFromSession(Resources.MisNotas);//Como aprovecho parte de la key para saber el nonce del AES y este nonce se genera automáticamente y siempre es distinto, no me lo va a sobreescribir en caché, me va a crear un NotasCache cada vez!!!
                SetSessionItem(Resources.MisNotas, cached);
            }
            return(SimpleJSONFeedback(tuple.Item1));
        }
        public NotasCache UpdateCache(NotasCache cached, NotaDTO updated)
        {
            NotaDTO mod = null;

            if (updated.Anchor)
            {
                if (cached.anchored.Any(nota => nota.NotaId == updated.NotaId))//No habría cambiado la prioridad
                {
                    mod = cached.anchored.First(nota => nota.NotaId == updated.NotaId);
                }
                else//eliminar y acoplar en el otro grupo
                {
                    mod = cached.notAnchored.First(nota => nota.NotaId == updated.NotaId);
                    cached.anchored.Add(mod);
                    cached.anchored = cached.anchored.OrderByDescending(nota => nota.CDT).ToList();
                    cached.notAnchored.Remove(mod);
                }
            }
            else
            {
                if (cached.notAnchored.Any(nota => nota.NotaId == updated.NotaId))//No habría cambiado la prioridad
                {
                    mod = cached.notAnchored.First(nota => nota.NotaId == updated.NotaId);
                }
                else//eliminar y acoplar en el otro grupo
                {
                    mod = cached.anchored.First(nota => nota.NotaId == updated.NotaId);
                    cached.notAnchored.Add(mod);
                    cached.notAnchored = cached.notAnchored.OrderByDescending(nota => nota.CDT).ToList();
                    cached.anchored.Remove(mod);
                }
            }
            mod.NoteContent = updated.NoteContent;
            mod.LUDT        = DateTime.Now;
            return(cached);
        }