Exemple #1
0
        public static bool Insert(DTOs.CustomerDTO customer)
        {
            List <Models.Entity.Profile> db = GetData();

            Models.Entity.Profile newCustomer = customer.Map();

            Models.Civil.Document cpf =
                (from document in newCustomer.Documents
                 where document.Name.ToLower() == "cpf"
                 select document).FirstOrDefault();

            if (cpf != null)
            {
                Models.Entity.Profile existingUser =
                    (from profile in db
                     from document in profile.Documents
                     where document.Name.ToLower() == "cpf" &&
                     document.Value == cpf.Value
                     select profile).FirstOrDefault();

                if (existingUser != null)
                {
                    return(false);
                }
            }

            newCustomer.NewId();
            db.Add(newCustomer);
            UpdateData(db);

            return(true);
        }
Exemple #2
0
        public static bool Update(DTOs.CustomerDTO customer)
        {
            List <Models.Entity.Profile> db = GetData();

            Models.Entity.Profile updateCustomer = customer.Map();

            for (int i = 0; i < db.Count; i++)
            {
                if (db[i].Id == updateCustomer.Id)
                {
                    db[i] = updateCustomer;
                    UpdateData(db);

                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        public static List <DTOs.CustomerDTO> GetAll()
        {
            List <Models.Entity.Profile> db     = GetData();
            List <DTOs.CustomerDTO>      result = new List <DTOs.CustomerDTO>();

            if (db.Count == 0)
            {
                return(null);
            }

            foreach (Models.Entity.Profile profile in db)
            {
                DTOs.CustomerDTO newCustomer = new DTOs.CustomerDTO();
                newCustomer.Map(profile);
                result.Add(newCustomer);
            }

            return(result);
        }
Exemple #4
0
        public static DTOs.CustomerDTO?SearchById(string id)
        {
            List <Models.Entity.Profile> db = GetData();

            Models.Entity.Profile search =
                (from profile in db
                 where profile.Id == id
                 select profile).FirstOrDefault();

            if (search != null)
            {
                DTOs.CustomerDTO result = new DTOs.CustomerDTO();
                result.Map(search);

                return(result);
            }

            return(null);
        }