public int CopyDictionary(int dictionaryId, int userId)
        {
            var translations = TranslationsRepository.GetTranslationsForDictionary(dictionaryId).ToList();
            var dictionary   = DictionariesRepository.GetById(dictionaryId);

            Context.Entry(dictionary).State = EntityState.Detached;

            dictionary.Id                 = 0;
            dictionary.UserId             = userId;
            dictionary.ParentDictionaryId = dictionaryId;
            dictionary.User               = null;
            dictionary.Date               = DateTime.Today;
            dictionary.IsPublic           = false;
            DictionariesRepository.Insert(dictionary);
            DictionariesRepository.Save();

            translations.ForEach(translation =>
            {
                Context.Entry(translation).State = EntityState.Detached;
                translation.Id           = 0;
                translation.DictionaryId = dictionary.Id;
                translation.Dictionary   = null;
            });

            var check = TranslationsRepository.Insert(translations) && TranslationsRepository.Save();

            return(check ? dictionary.Id : -1);
        }
        public bool UpdateDictionary(int dictionaryId)
        {
            var dictionary = DictionariesRepository.GetById(dictionaryId);

            if (dictionary.ParentDictionaryId == null)
            {
                return(false);
            }

            var currentTranslations = TranslationsRepository.GetTranslationsForDictionary(dictionaryId).ToList();
            var parentTranslations  = TranslationsRepository.GetTranslationsForDictionary(dictionary.ParentDictionaryId.Value).ToList();
            var toAdd = parentTranslations.Except(currentTranslations).ToList();

            toAdd.ForEach(trans =>
            {
                var translation = new Translation
                {
                    DictionaryId   = dictionaryId,
                    FirstLangWord  = trans.FirstLangWord,
                    SecondLangWord = trans.SecondLangWord
                };
                TranslationsRepository.Insert(translation);
            });

            return(TranslationsRepository.Save());;
        }
        public ActionResult Get(int id)
        {
            var dictionary = DictionariesRepository.GetById(id);

            if (dictionary.IsPublic)
            {
                AccessGuardian(Roles.AccessUser);
            }
            else
            {
                AccessGuardian(Roles.AccessUser, dictionary.UserId);
            }
            return(JsonHelper.Success(DictionariesRepository.GetById(id)));
        }
        public FileResult Export(int dictionaryId)
        {
            var dictionary = DictionariesRepository.GetById(dictionaryId);

            if (dictionary.IsPublic)
            {
                AccessGuardian(Roles.AccessUser);
            }
            else
            {
                AccessGuardian(Roles.AccessUser, dictionary.UserId);
            }

            var stream = DataExchangeService.ExportDictionary(dictionaryId);

            /*
             * var result = new HttpResponseMessage(HttpStatusCode.OK)
             * {
             *  Content = new ByteArrayContent(stream.ToArray())
             * };
             * result.Content.Headers.ContentDisposition =
             *  new ContentDispositionHeaderValue("attachment")
             *  {
             *      FileName = $"slownik_{dictionaryId}_{DateTime.Today}.csv"
             *  };
             * result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
             *
             * return result;*/

            Context.Response.ContentType = "application/octet-stream";
            var result = new FileContentResult(stream.ToArray(), "application/octet-stream")
            {
                FileDownloadName = $"eksport_slownik_{dictionaryId}_{DateTime.Now:dd-MM-yyyy}.csv"
            };

            return(result);
        }
        public ActionResult Delete(int id)
        {
            AccessGuardian(new AccessRole(Roles.AccessUser, DictionariesRepository.GetById(id).UserId));

            return(JsonHelper.Response(DictionariesService.Delete(id)));
        }