Exemplo n.º 1
0
        public MemberEntity Delete(Guid member_id)
        {
            var member = new MemberEntity()
            {
                member_id = member_id
            };

            var data = _context.member.Remove(member);

            _context.SaveChanges();

            return(member);
        }
Exemplo n.º 2
0
        public MemberEntity Update(Guid id, MemberEntity modelUpdate)
        {
            var data = _context.member.Find(id);

            data.firstname = modelUpdate.firstname;
            data.lastname  = modelUpdate.lastname;
            //data.created_by = modelUpdate.created_by;
            //data.created_at = modelUpdate.created_at;
            data.updated_at = DateTime.Now;

            _context.SaveChanges();

            return(data);
        }
Exemplo n.º 3
0
        public MemberEntity Create(MemberEntity model)
        {
            var member = _context.member.Where(x => x.email == model.email).FirstOrDefault();

            if (member == null)
            {
                //model.member_id = Guid.NewGuid();
                model.password = StringToMD5(model.password);
                _context.member.Add(model);

                //add permission
                var permission = new PermissionEntity();

                permission.permission_id   = Guid.NewGuid();
                permission.member_id       = model.member_id;
                permission.permission_type = "member";
                permission.created_at      = DateTime.Now;

                _context.permission.Add(permission);

                _context.SaveChanges();

                model.password = null;
                return(model);
            }
            else
            {
                if (member.email == model.email)
                {
                    throw new Exception("อีเมลนี้มีในระบบแล้ว");
                }
                else
                {
                    throw new Exception("Error");
                }
            }
        }