Пример #1
0
 private static void MapToDbProperties(ImaginaryUserDto sourceDto, ImaginaryUsers targetDbItem)
 {
     targetDbItem.CreateDate = sourceDto.CreateDate;
     targetDbItem.CreateUser = sourceDto.CreateUser;
     targetDbItem.UpdateDate = sourceDto.UpdateDate;
     targetDbItem.UpdateUser = sourceDto.UpdateUser;
 }
Пример #2
0
 private static void MapBaseProperties(ImaginaryUsers source, ImaginaryUserDto target)
 {
     target.Id         = source.Id;
     target.CreateDate = source.CreateDate;
     target.CreateUser = source.CreateUser;
     target.UpdateDate = source.UpdateDate;
     target.UpdateUser = source.UpdateUser;
 }
Пример #3
0
        public static ImaginaryUserDto Update(ImaginaryUserDto updatedUser)
        {
            updatedUser.SetBasePropertiesForUpdate();
            ImaginaryUsers original = null;

            using (TestDbEntities db = new TestDbEntities())
            {
                original = db.ImaginaryUsers.Find(updatedUser.Id);

                original.Status      = updatedUser.Status.ToString();
                original.Username    = updatedUser.Username;
                original.BirthDate   = updatedUser.BirthDate;
                original.Email       = updatedUser.Email;
                original.Gender      = updatedUser.Gender;
                original.Name        = updatedUser.Name;
                original.PhoneNumber = updatedUser.PhoneNumber;
                original.Surname     = updatedUser.Surname;
                original.Password    = updatedUser.Password;
                original.IpAddress   = updatedUser.IpAddress;
                original.Cookie      = updatedUser.Cookie;

                MapToDbProperties(updatedUser, original);

                db.SaveChanges();
            }

            var result = new ImaginaryUserDto
            {
                BirthDate   = original.BirthDate ?? DateTime.MinValue,
                Email       = original.Email,
                Gender      = original.Gender,
                Name        = original.Name,
                PhoneNumber = original.PhoneNumber,
                Status      = (UserStatus)Enum.Parse(typeof(UserStatus), original.Status),
                Surname     = original.Surname,
                Username    = original.Username,
                Password    = original.Password,
                IpAddress   = original.IpAddress,
                Cookie      = original.Cookie
            };

            MapBaseProperties(original, result);

            return(result);
        }
Пример #4
0
        public static ImaginaryUserDto Insert(ImaginaryUserDto newUser)
        {
            newUser.SetBaseProperties();
            ImaginaryUsers dbRecord = new ImaginaryUsers
            {
                Username    = newUser.Username,
                BirthDate   = newUser.BirthDate,
                Email       = newUser.Email,
                Gender      = newUser.Gender,
                Name        = newUser.Name,
                PhoneNumber = newUser.PhoneNumber,
                Status      = newUser.Status.ToString(),
                Surname     = newUser.Surname,
                Password    = newUser.Password,
                IpAddress   = newUser.IpAddress,
                Cookie      = newUser.Cookie
            };

            MapToDbProperties(newUser, dbRecord);

            using (TestDbEntities db = new TestDbEntities())
            {
                db.ImaginaryUsers.Add(dbRecord);
                db.SaveChanges();
            }

            var result = new ImaginaryUserDto
            {
                BirthDate   = dbRecord.BirthDate ?? DateTime.MinValue,
                Email       = dbRecord.Email,
                Gender      = dbRecord.Gender,
                Name        = dbRecord.Name,
                PhoneNumber = dbRecord.PhoneNumber,
                Status      = (UserStatus)Enum.Parse(typeof(UserStatus), dbRecord.Status),
                Surname     = dbRecord.Surname,
                Username    = dbRecord.Username,
                Password    = dbRecord.Password,
                IpAddress   = dbRecord.IpAddress,
                Cookie      = dbRecord.Cookie
            };

            MapBaseProperties(dbRecord, result);

            return(result);
        }