public HttpResponseMessage UpdateAllocationSettings([FromBody] AllocationSettings allocationSettings)
        {
            if (allocationSettings == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid parameters!"));
            }

            if (_currentUserService.MemberType != MemberType.Admin && _currentUserService.MemberType != MemberType.Parent)
            {
                throw new UnauthorizedAccessException();
            }

            _allocationSettingsService.Update(allocationSettings);
            return(Request.CreateResponse(HttpStatusCode.OK, "Allocation settings saved successfully"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update allocation settings
        /// </summary>
        /// <param name="updatedSettings">Allocation settings</param>
        public void Update(AllocationSettings updatedSettings)
        {
            var totalAllocate = updatedSettings.Save + updatedSettings.Share + updatedSettings.Spend;

            if (totalAllocate != 100)
            {
                throw new InvalidParameterException("Total has to equal 100%, please adjust");
            }

            var allocationSettings = Repository.Table <AllocationSettings>().SingleOrDefault(m => m.Id == updatedSettings.Id);

            if (allocationSettings == null)
            {
                throw new ObjectNotFoundException("Allocation settings not found");
            }

            // Update
            allocationSettings.Save  = updatedSettings.Save;
            allocationSettings.Share = updatedSettings.Share;
            allocationSettings.Spend = updatedSettings.Spend;
            Repository.Update(allocationSettings);
        }