Exemple #1
0
        public async Task <ContractDto> CreateAsync(ContractDto create)
        {
            if (CheckEntity(create))
            {
                var property = await db.Properties.Where(c => c.Id == create.PropertyId).Include(e => e.Contract).FirstOrDefaultAsync();

                if (property != null)
                {
                    if (property.Sold)
                    {
                        throw new InvalidQueryParamsException("You can't create a contract for this property, because it has one.");
                    }
                    var result = db.Contracts.Add(mapper.Map <Contract>(create));
                    property.Sold = true;
                    await db.SaveChangesAsync();

                    return(mapper.Map <ContractDto>(result.Entity));
                }
                else
                {
                    throw new InvalidQueryParamsException();
                }
            }
            else
            {
                throw new InvalidQueryParamsException();
            }
        }
Exemple #2
0
        public async Task <PropertyDto> CreateAsync(PropertyDto create)
        {
            if (CheckEntity(create))
            {
                var result = db.Properties.Add(mapper.Map <Property>(create));
                await db.SaveChangesAsync();

                return(mapper.Map <PropertyDto>(result.Entity));
            }
            else
            {
                throw new InvalidQueryParamsException();
            }
        }
        public async Task <CommentDto> CreateAsync(CommentDto create)
        {
            if (CheckEntity(create))
            {
                var map    = mapper.Map <Comment>(create);
                var result = db.Comments.Add(map);
                await db.SaveChangesAsync();

                return(mapper.Map <CommentDto>(result.Entity));
            }
            else
            {
                throw new InvalidQueryParamsException();
            }
        }
Exemple #4
0
        public async Task <UserDto> CreateCustomerAsync(UserDto create)
        {
            if (CheckEntity(create))
            {
                var user = mapper.Map <User>(create);
                user.Id = Guid.NewGuid().ToString();
                var result = await userManager.CreateAsync(user, create.Password);

                if (!result.Succeeded)
                {
                    throw new DbNullException();
                }

                var currentUser = await userManager.FindByNameAsync(user.UserName);

                await userManager.AddToRoleAsync(currentUser, Roles.Customer);

                await db.SaveChangesAsync();

                return(mapper.Map <UserDto>(currentUser));
            }
            else
            {
                throw new InvalidQueryParamsException();
            }
        }