コード例 #1
0
        public bool add(Customer inCustomer, byte[] hashedPassword)
        {
            var newCustomer = new Customers()
            {
                Firstname = inCustomer.firstname,
                Lastname = inCustomer.lastname,
                Address = inCustomer.address,
                PostalareasId = Convert.ToInt16(inCustomer.postalcode),
                Password = hashedPassword,
                Phonenumber = inCustomer.phonenumber,
                Email = inCustomer.email
            };

            var db = new DatabaseContext();
            try
            {
                var existPostalcode = db.Postalareas.Find(Convert.ToInt16(inCustomer.postalcode));

                if(existPostalcode == null )
                {
                    var newPostalarea = new Postalareas()
                    {
                        PostalareasId = Convert.ToInt16(inCustomer.postalcode),
                        Postalarea = inCustomer.postalarea
                    };
                    newCustomer.Postalareas = newPostalarea;
                }
                db.Customers.Add(newCustomer);
                db.SaveChanges();
                return true;
            }
            catch (Exception fail)
            {
                return false;
            }
        }
コード例 #2
0
        public bool update(int id, Customer updateUser)
        {
            var db = new DatabaseContext();
            try
            {
                Customers cust = db.Customers.FirstOrDefault(u => u.Id == id);
           
                cust.Firstname = updateUser.firstname;
                cust.Lastname = updateUser.lastname;
                cust.Address = updateUser.address;
                cust.PostalareasId = Convert.ToInt16(updateUser.postalcode);
                cust.Phonenumber = updateUser.phonenumber;
                cust.Email = updateUser.email;
            
                var existPostalcode = db.Postalareas.Find(Convert.ToInt16(updateUser.postalcode));

                if (existPostalcode == null)
                {
                    var newPostalarea = new Postalareas()
                    {
                        PostalareasId = Convert.ToInt16(updateUser.postalcode),
                        Postalarea = updateUser.postalarea
                    };
                    cust.Postalareas = newPostalarea;
                }
                db.SaveChanges();
                return true;
            }
            catch (Exception fail)
            {
                return false;
               
            }
        }