Example #1
0
        public HttpResponseMessage SyncContacts([FromBody] SyncDataDTO syncData)
        {
            LogRequest(syncData);
            if (!ModelState.IsValid || syncData == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            if (syncData.Contacts.Count > 0)
            {
                var user = new NeeoUser(syncData.Uid);
                try
                {
                    var result = user.GetContactsState(syncData.MapModel());
                    if (result.Count == 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NoContent));
                    }
                    if (!syncData.Filtered)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, result.ConvertAll((MapContactStatusToContactStatusDTO))));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, result.ConvertAll((MapcontactStatusToContactSubscriptionDTO))));
                    }
                }
                catch (ApplicationException appExp)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }
                catch (Exception exp)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }