2015-12-08 22:57:38 -05:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
using Bit.Api.Utilities;
|
|
|
|
|
|
using Bit.Core.Domains;
|
2016-05-21 17:16:22 -04:00
|
|
|
|
using Newtonsoft.Json;
|
2015-12-08 22:57:38 -05:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Models
|
|
|
|
|
|
{
|
|
|
|
|
|
public class FolderRequestModel
|
|
|
|
|
|
{
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
[EncryptedString]
|
2015-12-30 21:40:19 -05:00
|
|
|
|
[StringLength(300)]
|
2015-12-08 22:57:38 -05:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
2016-05-21 17:16:22 -04:00
|
|
|
|
public Cipher ToCipher(string userId = null)
|
2015-12-08 22:57:38 -05:00
|
|
|
|
{
|
2016-05-21 17:16:22 -04:00
|
|
|
|
return new Cipher
|
2015-12-08 22:57:38 -05:00
|
|
|
|
{
|
2016-05-21 17:16:22 -04:00
|
|
|
|
UserId = new Guid(userId),
|
|
|
|
|
|
Data = JsonConvert.SerializeObject(new CipherDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }),
|
|
|
|
|
|
Type = Core.Enums.CipherType.Folder
|
2015-12-08 22:57:38 -05:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-21 17:16:22 -04:00
|
|
|
|
public Cipher ToCipher(Cipher existingFolder)
|
2015-12-08 22:57:38 -05:00
|
|
|
|
{
|
2016-05-21 17:16:22 -04:00
|
|
|
|
existingFolder.Data = JsonConvert.SerializeObject(new CipherDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
|
|
|
|
|
existingFolder.Type = Core.Enums.CipherType.Folder;
|
2015-12-08 22:57:38 -05:00
|
|
|
|
|
|
|
|
|
|
return existingFolder;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|