Beispiel #1
0
        public JsonResult Update(string model)
        {
            if (!AuthorizationProvider.CanEditRevenue())
            {
                return(Forbidden());
            }

            // parameter is passed in as a model with Json string
            var entity = JsonConvert.DeserializeObject <ResolutionRevenueModel>(model);

            try
            {
                if (!string.IsNullOrEmpty(entity.ConfirmationCode))
                {
                    var provider     = new ReservationRevenueProvider(_dbContext);
                    var propertycode = provider.GetPropertyCodeByConfirmationCode(entity.ConfirmationCode);
                    if (!string.IsNullOrEmpty(propertycode))
                    {
                        entity.PropertyCode = propertycode;
                    }
                }

                var dataProvider = new ResolutionRevenueProvider(_dbContext);
                dataProvider.Update(entity.ResolutionId, entity);
                dataProvider.Commit();

                return(Json(entity, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Saving Resolution {0:d} fails. {1} - {2}", entity.ResolutionId, ex.Message, innerErrorMessage);
                return(InternalError(message, "fail", ex));
            }
        }