Example #1
0
        //Update
        public bool UpdateAppEntity(string devId, string appName, string entityName, AppEntity appEntity)
        {
            AppEntityDTO ae = GetAppEntity(devId, appName, entityName);

            try
            {
                if (ae != null)
                {
                    //Prevent user from changing references
                    appEntity.AppId    = ae.AppId;
                    appEntity.EntityId = ae.EntityId;

                    _unitOfWork.EntityRepository.Update(appEntity);
                    foreach (EntityField ef in appEntity.EntityFields)
                    {
                        _unitOfWork.FieldRepository.Update(ef);
                    }
                    _unitOfWork.Save();
                    return(true);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(false);
        }
Example #2
0
        public IHttpActionResult DeleteAppEntity([FromUri] string userid, [FromUri] string entityname, [FromUri] string name)
        {
            AppEntityDTO appEntity = _appEntityService.DeleteAppEntity(userid, name, entityname);

            if (appEntity != null)
            {
                return(StatusCode(HttpStatusCode.Accepted));
            }
            else
            {
                return(NotFound());
            }
        }
Example #3
0
        public IHttpActionResult InsertAppEntity([FromUri] string userid, [FromUri] string name, [FromBody] AppEntity appEntity)
        {
            AppEntityDTO da = _appEntityService.InsertAppEntity(userid, name, appEntity);

            if (da != null)
            {
                return(Created(new Uri(Url.Link(Constants.GET_ENTITY_BY_NAME, new { userid, name, entityname = da.EntityName })), da));
            }
            else
            {
                return(BadRequest("This entity already exists in the specified app for this user"));
            }
        }
Example #4
0
        //Delete
        public AppEntityDTO DeleteAppEntity(string devId, string appName, string entityName)
        {
            AppEntityDTO dto       = new AppEntityDTO();
            DevAppDTO    da        = GetDevAppById(devId, appName);
            AppEntity    appEntity = _unitOfWork.EntityRepository.GetWithInclude().Where(d => d.AppId == da.AppId).Where(d => d.EntityName.Equals(entityName)).FirstOrDefault();

            if (appEntity != null)
            {
                dto = _unitOfWork.EntityRepository.Delete(appEntity);
                _unitOfWork.Save();
            }
            return(dto);
        }
Example #5
0
        public IHttpActionResult GetAppEntity([FromUri] string userid, [FromUri] string entityname, [FromUri] string name)
        {
            AppEntityDTO appEntityDTO = new AppEntityDTO();

            appEntityDTO = _appEntityService.GetAppEntity(userid, name, entityname);
            if (appEntityDTO != null)
            {
                return(Ok(appEntityDTO));
            }
            else
            {
                return(NotFound());
            }
        }
        //Read
        public EntityFieldDTO GetEntityField(string devId, string appName, string entityName, string fieldName)
        {
            AppEntityDTO app = GetAppEntity(devId, appName, entityName);

            try
            {
                if (app != null)
                {
                    return(_unitOfWork.FieldRepository.GetWithInclude().Where(d => d.DeactivationFlag.Equals(false))
                           .Where(d => d.EntityId == app.EntityId).Where(d => d.FieldName.Equals(fieldName))
                           .FirstOrDefault());
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(null);
        }
        //Delete
        public EntityFieldDTO DeleteEntityField(string devId, string appName, string entityName, string fieldName)
        {
            EntityFieldDTO dto = new EntityFieldDTO();
            AppEntityDTO   da  = GetAppEntity(devId, appName, entityName);

            try
            {
                EntityField entityField = _unitOfWork.FieldRepository.GetWithInclude().Where(d => d.EntityId == da.EntityId).Where(d => d.FieldName.Equals(fieldName)).FirstOrDefault();
                if (entityField != null)
                {
                    dto = _unitOfWork.FieldRepository.Delete(entityField);
                    _unitOfWork.Save();
                    return(dto);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(null);
        }
        //Activation
        public bool SetEntityFieldActive(string devId, string appName, string entityName, string fieldName, bool val)
        {
            AppEntityDTO da = GetAppEntity(devId, appName, entityName);
            EntityField  ef = _unitOfWork.FieldRepository.GetWithInclude().Where(d => d.EntityId == da.EntityId).Where(d => d.FieldName.Equals(fieldName)).FirstOrDefault();

            try
            {
                if (ef != null)
                {
                    ef.DeactivationFlag = val;
                    _unitOfWork.FieldRepository.Update(ef);
                    _unitOfWork.Save();
                    return(true);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(false);
        }
        //Create
        public EntityFieldDTO InsertEntityField(string devId, string appName, string entityName, EntityField entityField)
        {
            EntityFieldDTO dto = new EntityFieldDTO();
            AppEntityDTO   app = GetAppEntity(devId, appName, entityName);

            try
            {
                entityField.EntityId = app.EntityId;
                EntityField check = _unitOfWork.FieldRepository.GetWithInclude().Where(d => d.FieldName.Equals(entityField.FieldName)).Where(d => d.EntityId.Equals(app.EntityId)).FirstOrDefault();
                if (check != null)
                {
                    return(null);
                }
                dto = _unitOfWork.FieldRepository.Insert(entityField);
                _unitOfWork.Save();
            }
            catch (Exception e)
            {
                throw e;
            }
            return(dto);
        }
Example #10
0
        //Create
        public AppEntityDTO InsertAppEntity(string devId, string appName, AppEntity appEntity)
        {
            AppEntityDTO dto = new AppEntityDTO();
            DevAppDTO    app = GetDevAppById(devId, appName);

            try
            {
                appEntity.AppId = app.AppId;
                AppEntity check = _unitOfWork.EntityRepository.GetWithInclude().Where(d => d.EntityName.Equals(appEntity.EntityName)).Where(d => d.AppId.Equals(app.AppId)).FirstOrDefault();
                if (check != null)
                {
                    return(null);
                }
                dto = _unitOfWork.EntityRepository.Insert(appEntity);
                _unitOfWork.Save();
            }
            catch (Exception e)
            {
                throw e;
            }
            return(dto);
        }
        public IHttpActionResult GetMockData([FromUri] string userid, [FromUri] string entityname, [FromUri] string name)
        {
            AppEntityDTO appEntityDTOs = new AppEntityDTO();

            appEntityDTOs = _service.GetAppEntity(userid, name, entityname);
            List <string> fieldNames = new List <string>();
            List <string> fieldTypes = new List <string>();

            foreach (EntityFieldDTO ef in appEntityDTOs.EntityFields)
            {
                fieldNames.Add(ef.FieldName);
                fieldTypes.Add(ef.FieldType);
            }
            _lib = new MockBuilder(fieldNames.ToArray(), fieldTypes.ToArray(), appEntityDTOs.EntityName);
            if (appEntityDTOs != null)
            {
                return(Ok(_lib.GetMocks()));
            }
            else
            {
                return(NotFound());
            }
        }