Example #1
0
        public Boolean saveEntry(Model.Entry pEntry)
        {
            Boolean result = false;

            Log.Information("Entry object: userId: " + pEntry.user_id + ", typeID: " + pEntry.typeId + ", userID: " + pEntry.user_id + ", title: " + pEntry.title + ", description: " + pEntry.entry_abstract + ", topicNAme: " + pEntry.topic);

            List <Model.Topic> topicList = new List <Model.Topic>();

            topicList = getTopics();
            foreach (Model.Topic topic in topicList)
            {
                if (topic.topicName == pEntry.topic)
                {
                    pEntry.topicId = topic.topicId;
                }
            }
            // No topicID => New topic
            if (pEntry.topicId == 0)
            {
                saveTopic(pEntry.topic);
            }

            // Get topic_id, ugly -> improve later
            topicList = getTopics();
            foreach (Model.Topic topic in topicList)
            {
                if (topic.topicName == pEntry.topic)
                {
                    pEntry.topicId = topic.topicId;
                }
            }


            var connection = new SQLiteConnection(sConnectionString);

            connection.Open();

            var command = new SQLiteCommand(connection);

            command.CommandText = "INSERT INTO entry(user_id, topic_id, type_id, title, description) " +
                                  "VALUES(@user_id, @topic_id, @type_id, @title, @desc)";
            command.Parameters.AddWithValue("@user_id", pEntry.user_id);
            command.Parameters.AddWithValue("@topic_id", pEntry.topicId);
            command.Parameters.AddWithValue("@type_id", pEntry.typeId);
            command.Parameters.AddWithValue("@title", pEntry.title);
            command.Parameters.AddWithValue("@topic_id", pEntry.topicId);
            command.Parameters.AddWithValue("@desc", pEntry.entry_abstract);
            //command.Parameters.AddWithValue("@crDatec", ); ;

            command.Prepare();
            command.ExecuteNonQuery();

            connection.Close();

            return(result);
        }
        public EntryDetailsPresenter(IEntryDetailsView view, IClipboardService clipboardService, IAlertDisplayer alertDisplayer, Model.Entry entry)
        {
            this.View             = view;
            this.Entry            = entry;
            this.ClipboardService = clipboardService;
            this.AlertDisplayer   = alertDisplayer;

            this.View.Entry                    = entry;
            this.View.ShowHidePassword        += OnShowHidePassword;
            this.View.CopyPasswordToClipboard += OnCopyPasswordToClipboard;
        }
        public JsonResult AddOrEditEntry(EntryEditViewModel model)
        {
            SyncContext.Lock();
            try
            {
                using (var masterPassword = SessionContext.GetMasterPassword())
                {
                    if (ModelState.IsValid)
                    {
                        var currentVaultName = SessionContext.GetCurrentVaultName();
                        var vaultRepository  = VaultRepositoryFactory.CreateInstance();
                        var vault            = vaultRepository.GetVault(currentVaultName, masterPassword);
                        var vaultManipulator = this.VaultManipulatorFactory.CreateInstance(vault);

                        var entry = vaultManipulator.GetEntryById(Guid.Parse(model.Id));

                        bool isNew = false;
                        if (entry == null)
                        {
                            entry    = new Model.Entry();
                            entry.Id = Guid.Parse(model.Id);
                            isNew    = true;
                        }

                        entry.Title       = model.Title;
                        entry.UserName    = model.UserName;
                        entry.Password    = model.Password;
                        entry.Url         = model.Url;
                        entry.Description = model.Description;

                        if (isNew)
                        {
                            Guid parentId = Guid.Parse(model.ParentId);
                            vaultManipulator.AddEntry(parentId, entry);
                        }
                        else
                        {
                            vaultManipulator.UpdateEntry(entry);
                        }

                        vaultRepository.SaveVault(vault, masterPassword);
                        return(Json(new { success = true }));
                    }
                    else
                    {
                        return(Json(new { success = false }));
                    }
                }
            }
            finally
            {
                SyncContext.Release();
            }
        }
Example #4
0
        /// <summary>
        /// Переводит entry из серверной модели в клиентскую
        /// </summary>
        /// <param name="modelEntry">Entry в клиентской модели</param>
        /// <returns>Entry в клиентской модели</returns>
        public static Client.Entry Convert(Model.Entry modelEntry)
        {
            if (modelEntry == null)
            {
                throw new ArgumentNullException();
            }

            Client.Status status;

            switch (modelEntry.Status)
            {
            case Model.Status.Active:
                status = Client.Status.Active;
                break;

            case Model.Status.Pending:
                status = Client.Status.Pending;
                break;

            case Model.Status.Revoked:
                status = Client.Status.Revoked;
                break;

            case Model.Status.Finished:
                status = Client.Status.Finished;
                break;

            default:
                throw new ArgumentOutOfRangeException(modelEntry.Status.ToString());
            }

            var clientEntry = new Client.Entry
            {
                UserId     = modelEntry.UserId,
                Id         = modelEntry.Id,
                ActivityId = modelEntry.ActivityId,
                Status     = status
            };

            return(clientEntry);
        }
Example #5
0
        public static async Task <Model.Entry> GetEntryAsync(int?Id)
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.GetAsync(apiUrl + "/Entries/" + Id);

                if (response.IsSuccessStatusCode)
                {
                    var data = await response.Content.ReadAsStringAsync();

                    Model.Entry entry = Newtonsoft.Json.JsonConvert.DeserializeObject <Model.Entry>(data);
                    return(entry);
                }
                else
                {
                    throw new HttpRequestException(response.ToString());
                }
            }
        }
        public static Model.Entry ConvertToModel(this Data.Entities.Entry data)
        {
            var model = new Model.Entry
            {
                Id         = data.Id,
                SourceId   = data.SourceId,
                PostId     = data.PostId,
                Url        = data.Url,
                FileName   = data.FileName,
                Processed  = data.Processed,
                Downloaded = data.Downloaded,
                Active     = data.Active,
                Deleted    = data.Deleted
            };

            if (data.Source != null)
            {
                model.Source = data.Source.ConvertToModel();
            }

            return(model);
        }