Exemplo n.º 1
0
        public async Task <IHttpActionResult> EditCompanyMember(CompanyMemberViewModel objCompanyMemberViewModel)
        {
            IHttpActionResult returnResult;

            if (this.Validation(objCompanyMemberViewModel, out returnResult))
            {
                return(returnResult);
            }

            var checkEmailExist = await this.userRepository.CheckEmailExist(objCompanyMemberViewModel.Email);

            if (!checkEmailExist)
            {
                return(this.Ok(
                           ApiResponse.SetResponse(ApiResponseStatus.Error, "User not found. please register first!!", null)));
            }

            var objCompanyMember = await this.companyMemberRepository.CheckUserExist(
                objCompanyMemberViewModel.CompanyId,
                objCompanyMemberViewModel.Email);

            if (objCompanyMember)
            {
                return(this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Error, "Member already exist!!", null)));
            }

            return(await this.companyMemberRepository.EditCompanyMember(objCompanyMemberViewModel)
                       ? this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Ok, "Member updated successfully!!", null))
                       : this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Error, "Company Member not found!!", null)));
        }
Exemplo n.º 2
0
        public async Task <bool> AddCompanyMember(CompanyMemberViewModel objCompanyMemberViewModel)
        {
            var objCompanyMember = new CompanyMember
            {
                UserId      = objCompanyMemberViewModel.UserId,
                CompanyId   = objCompanyMemberViewModel.CompanyId,
                CreatedDate = DateTime.Now
            };

            this.entities.CompanyMembers.Add(objCompanyMember);
            await this.entities.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 3
0
        private bool Validation(CompanyMemberViewModel objCompanyMemberViewModel, out IHttpActionResult returnResult)
        {
            if (objCompanyMemberViewModel.Email.IsEmpty())
            {
                returnResult = this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Error, "Enter email address", null));
                return(true);
            }

            if (!objCompanyMemberViewModel.Email.IsEmail())
            {
                returnResult = this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Error, "Enter valid email", null));
                return(true);
            }

            returnResult = null;
            return(false);
        }
Exemplo n.º 4
0
        public async Task <bool> EditCompanyMember(CompanyMemberViewModel objCompanyMemberViewModel)
        {
            var objCompanyMember =
                await this.entities.CompanyMembers.FirstOrDefaultAsync(x => x.Id == objCompanyMemberViewModel.Id);

            if (objCompanyMember == null)
            {
                return(false);
            }

            objCompanyMember.CompanyId = objCompanyMemberViewModel.CompanyId;
            objCompanyMember.UserId    = objCompanyMemberViewModel.UserId;

            this.entities.Entry(objCompanyMember).State = EntityState.Modified;
            await this.entities.SaveChangesAsync();

            return(true);
        }