public static ServiceActionResult CreateSuccess(string sucessString)
        {
            ServiceActionResult a = new ServiceActionResult();

            if (string.IsNullOrEmpty(sucessString) == false)
            {
                a.message = sucessString;
            }
            return(a);
        }
Esempio n. 2
0
        public ServiceActionResult Exec(string methodName, [FromBody] FWPostBody p)
        {
            try
            {
                IServiceBase service = GetService();

                var method = service.GetType().GetMethod(methodName);
                if (method == null)
                {
                    throw new ServiceSecurityException();
                }
                else
                {
                    object result      = null;
                    var    mParameters = method.GetParameters();
                    Check.Assert(mParameters.Length <= 1, "Only services with one or less parameter is allowed");

                    if (mParameters.Length == 0)
                    {
                        result = method.Invoke(service, null);
                    }
                    else if (mParameters.Length == 1)
                    {
                        ParameterInfo param1 = null;
                        foreach (var item in mParameters)
                        {
                            param1 = item;
                        }
                        object parameterValue = FWUtils.EntityUtils.ConvertStringToObject(p.data, param1.ParameterType);

                        object[] methodParams = { parameterValue };
                        result = method.Invoke(service, methodParams);
                    }

                    if (result != null)
                    {
                        return(new ServiceActionResult(result));
                    }
                    else
                    {
                        return(ServiceActionResult.CreateSuccess(GetSuccessString(methodName)));
                    }
                }
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                return(UIUtils.GetExceptionActionResult(ex.InnerException));
            }
            catch (Exception ex)
            {
                return(UIUtils.GetExceptionActionResult(ex));
            }
        }
Esempio n. 3
0
        // DELETE api/entity_adk/5
        public virtual ServiceActionResult Delete(string id)
        {
            try
            {
                if (this.HasDefaultDelete == false)
                {
                    throw new ServiceSecurityException();
                }

                IServiceBase service = GetService();
                var          entity  = service.GetByID(id, new GetByIDParameters(GetSourceTypeEnum.Table, GetModeEnum.Load));
                service.Delete(entity, new DeleteParameters());
                return(ServiceActionResult.CreateSuccess(UIText.Base.EntityService.SuccessMsgs.General.Delete));
            }
            catch (Exception ex)
            {
                return(UIUtils.GetExceptionActionResult(ex));
            }
        }
Esempio n. 4
0
        // PUT api/entity_adk
        public virtual ServiceActionResult Insert([FromBody] FWPostBody p)
        {
            try
            {
                if (this.HasDefaultInsert == false)
                {
                    throw new ServiceSecurityException();
                }

                IServiceBase service = GetService();
                var          obj     = EntityFactory.GetEntityObject(service.EntityName, GetSourceTypeEnum.Table);
                FWUtils.EntityUtils.JsonDeserializeOnObject(p.data, obj, null, true);
                service.Insert(obj, new InsertParameters());
                return(ServiceActionResult.CreateSuccess(UIText.Base.EntityService.SuccessMsgs.General.Insert));
            }
            catch (Exception ex)
            {
                return(UIUtils.GetExceptionActionResult(ex));
            }
        }
Esempio n. 5
0
        // PUT api/entity_adk/5
        public virtual ServiceActionResult Update(string id, [FromBody] FWPostBody p)
        {
            try
            {
                if (this.HasDefaultUpdate == false)
                {
                    throw new ServiceSecurityException();
                }

                IServiceBase service = GetService();
                //object id = FWUtils.EntityUtils.GetObjectFieldValue(p.data)
                var obj = service.GetByID(id, new GetByIDParameters(GetSourceTypeEnum.Table));
                // TODO: Fix this function in a way that it reads default Update fields from the entity and updates only those fields
                FWUtils.EntityUtils.JsonDeserializeOnObject(p.data, obj, null, true);
                service.Update(obj, new UpdateParameters());
                return(ServiceActionResult.CreateSuccess(UIText.Base.EntityService.SuccessMsgs.General.Update));
            }
            catch (Exception ex)
            {
                return(UIUtils.GetExceptionActionResult(ex));
            }
        }