public async Task <EnterpriseBranch> AddBranch(AddBranchParameters enterpriseBranch)
        {
            var temp = await context.Enterprises.Include(i => i.Branches).FirstOrDefaultAsync(i => i.Id == enterpriseBranch.EnterpriseId);

            var tempBranch = new EnterpriseBranch();

            tempBranch.Name     = enterpriseBranch.Name;
            tempBranch.Street   = enterpriseBranch.Street;
            tempBranch.StreetNo = enterpriseBranch.StreetNo;
            tempBranch.Country  = enterpriseBranch.Country;
            tempBranch.City     = enterpriseBranch.City;
            tempBranch.ZipCode  = enterpriseBranch.ZipCode;

            temp.Branches.Add(tempBranch);

            return(tempBranch);
        }
示例#2
0
        public async Task <EnterpriseBranch> AddBranch(AddBranchParameters enterpriseBranch)
        {
            try
            {
                var temp = await repo.AddBranch(enterpriseBranch);

                if (temp != null)
                {
                    await unitOfWork.CompleteAsync();
                }
                return(temp);
            }
            catch
            {
                return(null);
            }
        }
        public async Task <IActionResult> AddBranch(AddBranchParameters enterpriseBranch)
        {
            if (ModelState.IsValid)
            {
                var temp = await branchService.AddBranch(enterpriseBranch);

                if (temp != null)
                {
                    return(Ok(temp));
                }
                else
                {
                    return(BadRequest(new { Message = "Something went wrong. Please, try again later." }));
                }
            }
            else
            {
                return(BadRequest(new { Message = "Invalid parameters supplied." }));
            }
        }