ofbapi/OFBButte.Application/Users/UpdateProfile.cs

40 lines
1.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using OFBButte.Application.Database;
using OFBButte.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OFBButte.Application.Users
{
public class UpdateProfile
{
private readonly IOFBContext context;
public UpdateProfile(IOFBContext context)
{
this.context = context;
}
public Profile Handle(string email, Profile profile)
{
// Get the user
var user = context.Users.Include(u => u.Profile).FirstOrDefault(u => u.Email == email);
if (user == null || user.Profile == null)
return null;
user.Profile.City = profile.City;
user.Profile.Country = profile.Country;
user.Profile.FirstName = profile.FirstName;
user.Profile.LastName = profile.LastName;
user.Profile.ModifiedDate = DateTime.Now;
user.Profile.State = profile.State;
user.Profile.Street = profile.Street;
user.Profile.Zip = profile.Zip;
context.SaveChanges();
return user.Profile;
}
}
}