/// <summary>
        /// Delete Employee by Id
        /// </summary>
        /// <param name="employeId"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel> DeleteEmployeeAsync(Guid?employeId)
        {
            if (employeId == null)
            {
                return(new InvalidParametersResultModel());
            }

            var employee = await _context.Employees.FirstOrDefaultAsync(x => x.Id == employeId);

            if (employee == null)
            {
                return(new NotFoundResultModel());
            }

            _context.Employees.Remove(employee);
            return(await _context.PushAsync());
        }
Example #2
0
        /// <summary>
        /// Delete industry
        /// </summary>
        /// <param name="industryId"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel> DeleteIndustryAsync(Guid?industryId)
        {
            if (industryId == null)
            {
                return(new InvalidParametersResultModel());
            }

            var industry = await _context.Industries.FirstOrDefaultAsync(x => x.Id == industryId);

            if (industry == null)
            {
                return(new NotFoundResultModel());
            }

            _context.Industries.Remove(industry);
            return(await _context.PushAsync());
        }
        /// <summary>
        /// Delete organization async
        /// </summary>
        /// <param name="organizationId"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel> DeleteOrganizationAsync(Guid?organizationId)
        {
            if (organizationId == null)
            {
                return(new InvalidParametersResultModel());
            }

            var organization = await _organizationContext.Organizations
                               .FirstOrDefaultAsync(x => x.Id == organizationId);


            if (organization == null)
            {
                return(new NotFoundResultModel());
            }

            _organizationContext.Organizations.Remove(organization);
            return(await _organizationContext.PushAsync());
        }
        /// <summary>
        /// Add new contact
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel <Guid> > AddNewContactAsync(ContactViewModel model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel <Guid>());
            }


            var existContact = await _organizationContext.Contacts.FirstOrDefaultAsync(x =>
                                                                                       x.FirstName.Trim().ToLower().Equals(model.FirstName.Trim().ToLower()) &&
                                                                                       x.LastName.Trim().ToLower().Equals(model.LastName.Trim().ToLower()) &&
                                                                                       x.Email.Trim().ToLower().Equals(model.Email.Trim().ToLower()) &&
                                                                                       x.OrganizationId.Equals(model.OrganizationId));

            if (existContact != null)
            {
                return new ResultModel <Guid> {
                           IsSuccess = false, Errors = new List <IErrorModel> {
                               new ErrorModel {
                                   Message = "Contact " + model.FirstName + " " + model.LastName + " exist"
                               }
                           }
                }
            }
            ;


            var newContact = new Contact
            {
                OrganizationId = model.OrganizationId,
                JobPositionId  = model.JobPositionId,
                Email          = model.Email,
                FirstName      = model.FirstName,
                LastName       = model.LastName,
                Phone          = model.Phone,
                Description    = model.Description,
            };

            await _organizationContext.Contacts.AddAsync(newContact);

            var result = await _organizationContext.PushAsync();

            return(new ResultModel <Guid> {
                IsSuccess = result.IsSuccess, Errors = result.Errors, Result = newContact.Id
            });
        }
        /// <summary>
        /// Add organization address
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel <Guid> > AddOrganizationAddressAsync(OrganizationAddressViewModel model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel <Guid>());
            }

            var organizationAddress = _mapper.Map <OrganizationAddress>(model);

            //    new OrganizationAddress
            //{
            //    OrganizationId = model.OrganizationId,
            //    CityId = model.CityId,
            //    Street = model.Street,
            //    Zip = model.Zip
            //};

            _context.OrganizationAddresses.Add(organizationAddress);
            var result = await _context.PushAsync();

            return(new ResultModel <Guid> {
                IsSuccess = result.IsSuccess, Errors = result.Errors, Result = organizationAddress.Id
            });
        }