refactor api models for other cipher types

This commit is contained in:
Kyle Spearrin
2017-09-21 10:52:23 -04:00
parent 12650a0ada
commit c58135bac5
8 changed files with 151 additions and 12 deletions

View File

@@ -0,0 +1,39 @@
using System;
using Bit.Core.Enums;
using Bit.Core.Models.Table;
using Newtonsoft.Json;
namespace Bit.Core.Models.Api
{
public class SecureNoteDataModel : CipherDataModel
{
public SecureNoteDataModel() { }
public SecureNoteDataModel(CipherRequestModel cipher)
{
Name = cipher.Name;
Notes = cipher.Notes;
Fields = cipher.Fields;
Type = cipher.SecureNote.Type;
}
public SecureNoteDataModel(Cipher cipher)
{
if(cipher.Type != CipherType.SecureNote)
{
throw new ArgumentException("Cipher is not correct type.");
}
var data = JsonConvert.DeserializeObject<SecureNoteDataModel>(cipher.Data);
Name = data.Name;
Notes = data.Notes;
Fields = data.Fields;
Type = data.Type;
}
public SecureNoteType Type { get; set; }
}
}