ofbapi/OFBButte.Application/Users/AddProfile.cs

56 lines
1.7 KiB
C#

using OFBButte.Application.Base;
using OFBButte.Application.Codes;
using OFBButte.Application.Configuration;
using OFBButte.Application.Database;
using OFBButte.Entities;
using System;
using System.Collections.Generic;
using System.Text;
namespace OFBButte.Application.Users
{
public class AddProfile: AuthorizeCommand
{
private readonly IOFBContext context;
private readonly ICodeGenerator codes;
public AddProfile(IAccess access, IOFBContext context, ICodeGenerator codes)
:base(access, Permission.AddProfile)
{
this.context = context;
this.codes = codes;
}
public Profile Handle(Profile profile)
{
base.Authorize();
return Handle(profile.FirstName, profile.LastName, profile.Street, profile.City, profile.State, profile.Zip, profile.Country);
}
public Profile Handle(string first, string last, string street, string city, string state, string zip, string country)
{
base.Authorize();
var profile = new Profile()
{
FirstName = first,
LastName = last,
Street = street,
City = city,
State = state,
Zip = zip,
Country = country,
ModifiedDate = DateTime.Now,
ProfileFederationCode = new ProfileFederationCode()
{
CreatedDate = DateTime.Now,
Code = codes.Generate()
}
};
context.Profiles.Add(profile);
context.SaveChanges();
return profile;
}
}
}