예제 #1
0
        /// <summary>
        /// Metodo para criar um registro
        /// </summary>
        /// <param name="form"></param>
        /// <returns>o Registro criado completo com seus repectivos ids</returns>
        public static async Task <RegisterViewModel> Register(RegisterViewModel form)
        {
            var dbRegister = await _Register.GetWhereAsync(new Func <Register, bool>((x) => x.CpfCnpj == form.Register.CpfCnpj && x.Email == form.Register.Email));

            if (dbRegister.Count().Equals(0))
            {
                _Register.AddDataBase(form.Register);

                form.Register = _Register.GetWhereAsync(new Func <Register, bool>((x) => x.CpfCnpj == form.Register.CpfCnpj && x.Email == form.Register.Email)).Result.FirstOrDefault();

                form.Address.IdRecord = form.Register.Id;

                _Address.AddDataBase(form.Address);

                form.Address = _Address.GetWhereAsync(new Func <Address, bool>((x) => x.IdRecord == form.Register.Id)).Result.FirstOrDefault();

                return(form);
            }

            return(null);
        }