Files
server/src/Api/Models/Request/CipherRequestModel.cs

62 lines
1.9 KiB
C#
Raw Normal View History

2015-12-08 22:57:38 -05:00
using System;
using System.ComponentModel.DataAnnotations;
using Bit.Api.Utilities;
2017-03-08 21:45:08 -05:00
using Bit.Core.Models.Table;
2015-12-08 22:57:38 -05:00
using Bit.Core.Enums;
using Newtonsoft.Json;
2015-12-08 22:57:38 -05:00
namespace Bit.Api.Models
{
public class CipherRequestModel
2015-12-08 22:57:38 -05:00
{
public CipherType Type { get; set; }
[Required]
[StringLength(36)]
2015-12-08 22:57:38 -05:00
public string Id { get; set; }
[StringLength(36)]
2015-12-08 22:57:38 -05:00
public string FolderId { get; set; }
[Required]
[EncryptedString]
[StringLength(300)]
2015-12-08 22:57:38 -05:00
public string Name { get; set; }
[EncryptedString]
2016-10-13 18:45:33 -04:00
[StringLength(10000)]
2015-12-08 22:57:38 -05:00
public string Uri { get; set; }
[EncryptedString]
2016-10-13 18:45:33 -04:00
[StringLength(300)]
2015-12-08 22:57:38 -05:00
public string Username { get; set; }
[EncryptedString]
[StringLength(300)]
2015-12-08 22:57:38 -05:00
public string Password { get; set; }
[EncryptedString]
2016-10-13 18:45:33 -04:00
[StringLength(10000)]
2015-12-08 22:57:38 -05:00
public string Notes { get; set; }
public virtual Cipher ToCipher(Guid userId)
2015-12-08 22:57:38 -05:00
{
var cipher = new Cipher
2015-12-08 22:57:38 -05:00
{
Id = new Guid(Id),
UserId = userId,
FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId),
Type = Type
2015-12-08 22:57:38 -05:00
};
switch(Type)
2015-12-08 22:57:38 -05:00
{
case CipherType.Folder:
cipher.Data = JsonConvert.SerializeObject(new FolderDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
break;
2017-01-02 21:52:13 -05:00
case CipherType.Login:
cipher.Data = JsonConvert.SerializeObject(new LoginDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
break;
default:
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
2015-12-08 22:57:38 -05:00
}
return cipher;
2015-12-08 22:57:38 -05:00
}
}
}