예제 #1
0
        public async Task <IHttpActionResult> Create(PackagesCreateViewModel viewModel)
        {
            try
            {
                //Validation
                Validator result = PackageValidator.Create(viewModel);

                if (!result.Success)
                {
                    return(BadRequest(result.ErrorMessage));
                }
                //Create Package
                string  trackingCode = GenerateTrackingCode(viewModel);
                Package package      = viewModel.ToPackage(trackingCode);
                Db.Packages.Add(package);
                await Db.SaveChangesAsync();

                return(Ok("Package created successfully"));
            }
            catch
            {
                return(BadRequest("An error has occurred"));
            }
        }