Beispiel #1
0
        internal override void Export(string table)
        {
            //TODO: Incorporate new data
            base.Export(table);

            table = GetType().Name;


            var vals = new List <object>
            {
                Id,
                SiteId.DBExport(),
                SubregionId.DBExport(),
                FeatureLayerId.DBExport(),
                Coords.DBExport(),
                EntityId_Abuser.DBExport(),
                BodyHfiDs.DBExport(),
                ItemType.DBExport(Item.ItemTypes),
                ItemSubType.DBExport(Item.ItemSubTypes),
                ItemMat.DBExport(Item.Materials),
                HfId.DBExport(),
                AbuseType.DBExport()
            };



            Database.ExportWorldItem(table, vals);
        }
Beispiel #2
0
        public async Task <ResponseStatus> Label(string userId, bool isBad, AbuseType abuseType, string description = "", string analyst = "", string source = "")
        {
            var baseObject = new ExpandoObject() as IDictionary <string, Object>;

            baseObject.Add("$abuse_type", abuseType);

            baseObject.Add("$api_key", _apiKey);
            baseObject.Add("$is_bad", isBad);

            if (!String.IsNullOrEmpty(analyst))
            {
                baseObject.Add("$analyst", analyst);
            }

            if (!String.IsNullOrEmpty(source))
            {
                baseObject.Add("$source", source);
            }

            if (!String.IsNullOrEmpty(description))
            {
                baseObject.Add("$description", description);
            }

            var json = JsonConvert.SerializeObject(baseObject, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            var client = new HttpClient();

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = await client.PostAsync(string.Format(Globals.LabelsEndpoint, Uri.EscapeDataString(userId)), new StringContent(json, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                return(new ResponseStatus {
                    Success = true, StatusCode = (int)HttpStatusCode.OK
                });
            }

            if (response.StatusCode == HttpStatusCode.BadRequest)
            {
                var error = JsonConvert.DeserializeObject <SiftResponse>(response.Content.ReadAsStringAsync().Result);

                return(new ResponseStatus {
                    Success = false, SiftResponse = error, StatusCode = (int)HttpStatusCode.BadRequest
                });
            }


            return(new ResponseStatus {
                Success = false, StatusCode = (int)response.StatusCode
            });
        }
Beispiel #3
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            AbuseType abuseType = (AbuseType)value;

            if (abuseType == AbuseType.Payment)
            {
                writer.WriteValue("payment_abuse");
            }

            if (abuseType == AbuseType.Content)
            {
                writer.WriteValue("content_abuse");
            }

            if (abuseType == AbuseType.Promotion)
            {
                writer.WriteValue("promotion_abuse");
            }

            if (abuseType == AbuseType.Account)
            {
                writer.WriteValue("account_abuse");
            }
        }
        /// <summary>
        ///  Create a AbuseType
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public AbuseTypeVMDC CreateAbuseType(string currentUser, string user, string appID, string overrideID, AbuseTypeDC dc, IRepository <AbuseType> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService)
        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (null == dc)
                {
                    throw new ArgumentOutOfRangeException("dc");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    // Create a new ID for the AbuseType item
                    dc.Code = Guid.NewGuid();

                    // Map data contract to model
                    AbuseType destination = mappingService.Map <AbuseTypeDC, AbuseType>(dc);

                    // Add the new item
                    dataRepository.Add(destination);

                    // Commit unit of work
                    uow.Commit();

                    // Map model back to data contract to return new row id.
                    dc = mappingService.Map <AbuseType, AbuseTypeDC>(destination);
                }

                // Create aggregate data contract
                AbuseTypeVMDC returnObject = new AbuseTypeVMDC();

                // Add new item to aggregate
                returnObject.AbuseTypeItem = dc;

                return(returnObject);
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
        /// <summary>
        /// Retrieve a AbuseType with associated lookups
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        /// <returns></returns>
        public AbuseTypeVMDC GetAbuseType(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <AbuseType> dataRepository
                                          , IExceptionManager exceptionManager, IMappingService mappingService)

        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    AbuseTypeDC destination = null;

                    // If code is null then just return supporting lists
                    if (!string.IsNullOrEmpty(code))
                    {
                        // Convert code to Guid
                        Guid codeGuid = Guid.Parse(code);

                        // Retrieve specific AbuseType
                        AbuseType dataEntity = dataRepository.Single(x => x.Code == codeGuid);

                        // Convert to data contract for passing through service interface
                        destination = mappingService.Map <AbuseType, AbuseTypeDC>(dataEntity);
                    }



                    // Create aggregate contract
                    AbuseTypeVMDC returnObject = new AbuseTypeVMDC();

                    returnObject.AbuseTypeItem = destination;

                    return(returnObject);
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
        /// <summary>
        /// Update a AbuseType
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="lockID"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public void DeleteAbuseType(string currentUser, string user, string appID, string overrideID, string code, string lockID, IRepository <AbuseType> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService)
        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (string.IsNullOrEmpty(code))
                {
                    throw new ArgumentOutOfRangeException("code");
                }
                if (string.IsNullOrEmpty(lockID))
                {
                    throw new ArgumentOutOfRangeException("lockID");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    // Convert string to guid
                    Guid codeGuid = Guid.Parse(code);

                    // Find item based on ID
                    AbuseType dataEntity = dataRepository.Single(x => x.Code == codeGuid);

                    // Delete the item
                    dataRepository.Delete(dataEntity);

                    // Commit unit of work
                    uow.Commit();
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);
            }
        }