Esempio n. 1
0
        public bool Add(MemberServiceDTO memberDto)
        {
            if (memberDto == null)
                throw new ArgumentNullException("memberDto");

            User dbUser = _db.Query<User>().GetByName(memberDto.Name);
            if (dbUser != null)
                return false;

            _db.Insert(memberDto.CopyToDomainObject());
            return true;
        }
Esempio n. 2
0
        public bool Update(MemberServiceDTO memberDto)
        {
            if (memberDto == null)
                throw new ArgumentNullException("memberDto");

            Member dbMember = _db.Query<Member>().GetById(memberDto.UserID);

            User dbUser;
            if (dbMember.Name != memberDto.Name && ((dbUser = _db.Query<User>().GetByName(memberDto.Name)) != null) && dbUser.UserID != dbMember.UserID)
                return false;

            dbMember.UpdateDomainObjectFromDTO(memberDto);
            return true;
        }
Esempio n. 3
0
        public ActionResult Create(MemberServiceDTO memberDto)
        {
            // Verificar erros no modelo
            if (!ModelState.IsValid)
                return View("CreateUpdate", memberDto);

            // Verificar erros de negocio
            if (!_membersService.Add(memberDto))
            {
                ModelState.AddModelError("Name", "This name belongs to another user");
                return View("CreateUpdate", memberDto);
            }

            // Sucesso
            ViewBag.Who = memberDto.Name;
            return View("CUD", ActionEnum.Created);
        }