예제 #1
0
        public async Task <IHttpActionResult> Update(PackagesEditViewModel viewModel)
        {
            try
            {
                //Validation
                Package   package = Db.Packages.FirstOrDefault(p => p.Id == viewModel.Id);
                Validator result  = PackageValidator.Edit(viewModel, package);

                if (!result.Success)
                {
                    return(BadRequest(result.ErrorMessage));
                }

                viewModel.UpdatePackage(package);

                await Db.SaveChangesAsync();

                return(Ok("Package updated successfully"));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest("Package was changed by another user"));
            }
            catch
            {
                return(BadRequest("An error has occurred"));
            }
        }