public async Task CreateEvent(Guid eventId, CreateEventCommand createEventCommand)
        {
            await CreateUrlKey(eventId, createEventCommand.UrlKey);

            var document = new Document <EventDocument>
            {
                Id      = eventId.ToString(),
                Content = new EventDocument
                {
                    Subject     = createEventCommand.Subject,
                    UrlKey      = createEventCommand.UrlKey,
                    Description = createEventCommand.Description,
                    Address     = createEventCommand.Address,
                    Date        = createEventCommand.Date,
                    EndDate     = createEventCommand.EndDate,
                    Capacity    = createEventCommand.Capacity,
                    GroupId     = createEventCommand.GroupId,
                    Status      = EventStatuses.ACTIVE,
                    Location    = new EventLocationDocument
                    {
                        Lat = createEventCommand.Latitude,
                        Lon = createEventCommand.Longitude
                    }
                }
            };

            var documentResult = await _eventsBucket.InsertAsync(document);

            if (!documentResult.Success)
            {
                await DeleteUrlKey(createEventCommand.UrlKey);

                throw documentResult.Exception;
            }
        }
Exemplo n.º 2
0
        public async Task CreateGroup(Guid groupId, CreateGroupCommand createGroupCommand)
        {
            await CreateUrlKey(groupId, createGroupCommand.UrlKey);

            var document = new Document <GroupDocument>
            {
                Id      = groupId.ToString(),
                Content = new GroupDocument
                {
                    Name        = createGroupCommand.Name,
                    Description = createGroupCommand.Description,
                    UrlKey      = createGroupCommand.UrlKey,
                    OrganizerId = createGroupCommand.OrganizerId,
                    CityId      = createGroupCommand.CityId,
                    Topics      = createGroupCommand.TopicIds.Distinct().Select((x) => new GroupTopicDocument {
                        TopicId = x
                    }).ToList()
                }
            };

            var documentResult = await _groupsBucket.InsertAsync(document);

            if (!documentResult.Success)
            {
                await DeleteUrlKey(createGroupCommand.UrlKey);

                throw documentResult.Exception;
            }
        }
        public async Task <long> PersistEventAsync(string actorName, long index, object @event)
        {
            var evnt = new Event(actorName, index, @event);

            var res = await _bucket.InsertAsync(evnt.Key, evnt);

            return(index + 1);
        }
        public async Task Test_GetAsync()
        {
            var key   = "thekey";
            var value = "thevalue";

            await _bucket.RemoveAsync(key);

            await _bucket.InsertAsync(key, value);

            var result = await _bucket.GetAsync <string>(key);

            Assert.AreEqual(ResponseStatus.Success, result.Status);
        }
Exemplo n.º 5
0
        public async Task <string> GetStringAsync(IBucket bucket)
        {
            var doc = "";
            await bucket.InsertAsync("personKey", doc);

            return("someString");
        }
Exemplo n.º 6
0
        public Task WriteBatchAsync(IEnumerable <IDictionary <string, object> > json)
        {
            if (_bucket == null)
            {
                var cluster = new Cluster(new ClientConfiguration
                {
                    Servers = new List <Uri> {
                        _url
                    }
                });

                var authenticator = new PasswordAuthenticator(_username, _password);
                cluster.Authenticate(authenticator);
                _bucket = cluster.OpenBucket(_bucketName);
            }

            IEnumerable <IDocument <IDictionary <string, object> > > documents = json.Select(x =>
            {
                var retVal = new Document <IDictionary <string, object> >
                {
                    Id      = x["_id"] as string,
                    Content = new Dictionary <string, object>(x)
                };

                retVal.Content.Remove("_id");

                return(retVal);
            });


            return(_bucket.InsertAsync(documents.ToList()));
        }
Exemplo n.º 7
0
        public void SaveRequestAuditLog(HttpActionContext filterContext)
        {
            string requestParameter;

            using (var stream = filterContext.Request.Content.ReadAsStreamAsync().Result)
            {
                if (stream.CanSeek)
                {
                    stream.Position = 0;
                }
                requestParameter = filterContext.Request.Content.ReadAsStringAsync().Result;
            }
            AuditLogs auditLogs = new AuditLogs();

            auditLogs.Method           = filterContext.Request.Method.ToString();
            auditLogs.URL              = filterContext.Request.RequestUri.ToString();
            auditLogs.ControllerName   = filterContext.ControllerContext.ControllerDescriptor.ControllerName;
            auditLogs.Action           = filterContext.ActionDescriptor.ActionName;
            auditLogs.RequestParameter = JSONHelper.ToJSON(requestParameter);
            auditLogs.LogDate          = DataConversion.ConvertDateYMD(DateTime.Now.ToString());
            auditLogs.LogTime          = DateTime.Now.ToLongTimeString();

            var auditLogsDocs = new Document <AuditLogs>()
            {
                Id      = "Log_Request_" + DataConversion.ConvertYMDHMS(DateTime.Now.ToString()),
                Content = auditLogs
            };
            //WriteLog(auditLogs, "request");
            var result = _bucket.InsertAsync(auditLogsDocs);
        }
Exemplo n.º 8
0
        public async Task CreateCity(Guid cityId, CreateCityCommand createCityCommand)
        {
            var document = new Document <CityDocument>
            {
                Id      = cityId.ToString(),
                Content = new CityDocument
                {
                    Name     = createCityCommand.Name,
                    City     = createCityCommand.City,
                    Country  = createCityCommand.Country,
                    Location = new CityLocationDocument
                    {
                        Lat = createCityCommand.Latitude,
                        Lon = createCityCommand.Longitude
                    }
                }
            };

            var documentResult = await _citiesBucket.InsertAsync(document);

            if (!documentResult.Success)
            {
                throw documentResult.Exception;
            }
        }
        /// <summary>
        /// Writes a document representing a grain state object.
        /// </summary>
        /// <param name="collectionName">The type of the grain state object.</param>
        /// <param name="key">The grain id string.</param>
        /// <param name="entityData">The grain state data to be stored./</param>
        /// <returns>Completion promise for this operation.</returns>
        public async Task <string> Write(string collectionName, string key, string entityData, string eTag)
        {
            var   docID = GetDocumentID(collectionName, key);
            ulong realETag;

            if (ulong.TryParse(eTag, out realETag))
            {
                var r = await bucket.UpsertAsync <string>(docID, entityData, realETag);

                if (!r.Success)
                {
                    throw new Orleans.Storage.InconsistentStateException(r.Status.ToString(), eTag, r.Cas.ToString());
                }

                return(r.Cas.ToString());
            }
            else
            {
                var r = await bucket.InsertAsync <string>(docID, entityData);

                //check if key exist and we don't have the CAS
                if (!r.Success && r.Status == Couchbase.IO.ResponseStatus.KeyExists)
                {
                    throw new Orleans.Storage.InconsistentStateException(r.Status.ToString(), eTag, r.Cas.ToString());
                }
                else if (!r.Success)
                {
                    throw new System.Exception(r.Status.ToString());
                }
                return(r.Cas.ToString());
            }
        }
Exemplo n.º 10
0
        public async Task <User> Create(User user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new Exception("Password is required");
            }

            user.Created = DateTime.Now;
            user.Updated = DateTime.Now;
            if (string.IsNullOrEmpty(user.Id) || user.Id == "0")
            {
                user.Id = Guid.NewGuid().ToString();
            }
            var key = CreateKey(typeof(User), user.Id);

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            var result = await bucket.InsertAsync(key, user);

            if (!result.Success)
            {
                throw result.Exception;
            }

            return(result.Value);
        }
Exemplo n.º 11
0
        public async Task <IHttpActionResult> RegisterPassengerMessage(PassengerMessageModel model)
        {
            //Modified by Vishal on 23-07-2018 as per joe email
            if (string.IsNullOrEmpty(model.NameEN) && string.IsNullOrEmpty(model.NameAR))
            {
                return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "110-NameEN or NameAR is required"), new JsonMediaTypeFormatter()));
            }
            try
            {
                //Modified by Vishal on 24-07-2018 as per joe email
                if (string.IsNullOrEmpty(model.NameEN) && string.IsNullOrEmpty(model.NameAR))
                {
                    return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "110-Either nameEN or nameAR is required"), new JsonMediaTypeFormatter()));
                }
                if (!ModelState.IsValid)
                {
                    var modelErrors = new List <string>();
                    foreach (var modelState in ModelState.Values)
                    {
                        foreach (var modelError in modelState.Errors)
                        {
                            modelErrors.Add(modelError.ErrorMessage);
                        }
                    }
                    return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), modelErrors[0].ToString()), new JsonMediaTypeFormatter()));
                }

                var userKey = "PassengerMessage_" + model.EmailAddress;
                if (await _bucket.ExistsAsync(userKey))
                {
                    return(Content(HttpStatusCode.Conflict, MessageResponse.Message(HttpStatusCode.Conflict.ToString(), "105-The e-mail already exists"), new JsonMediaTypeFormatter()));
                }
                // call third part api to check Vehicle is valid or not
                var passengerMessageDoc = new Document <PassengerMessageModel>()
                {
                    Id      = userKey,
                    Content = new PassengerMessageModel
                    {
                        Action       = "ADD",
                        PassengerID  = userKey,
                        NameEN       = model.NameEN,
                        NameAR       = model.NameAR,
                        MobileNumber = model.MobileNumber,
                        EmailAddress = model.EmailAddress,
                    }
                };
                var result = await _bucket.InsertAsync(passengerMessageDoc);

                if (!result.Success)
                {
                    return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), result.Message), new JsonMediaTypeFormatter()));
                }
                return(Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), MessageDescriptions.Add, result.Document.Id), new JsonMediaTypeFormatter()));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter()));
            }
        }
 /// <summary>
 /// Stores the data.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public Task StoreAsync(string key, Token value)
 {
     return(_bucket.InsertAsync(TokenWrapper.TokenWrapperId(key), new TokenWrapper()
     {
         Id = key,
         Model = new Token()
     }));
 }
        public async Task CreateStarAsync(Star star)
        {
            if (star == null)
            {
                throw new ArgumentNullException(nameof(star));
            }

            star.Id = await GetNextStarIdAsync();

            var document = new Document <Star>
            {
                Id      = Star.GetKey(star.Id),
                Content = star
            };

            var result = await _bucket.InsertAsync(document);

            result.EnsureSuccess();
        }
        public async Task <Unit> Handle(NewProfileRequest request, CancellationToken cancellationToken)
        {
            await _bucket.InsertAsync(new Document <NewProfileEvent>
            {
                Id      = Guid.NewGuid().ToString(),
                Content = new NewProfileEvent(request)
            });

            return(Unit.Value);
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Store(Message message)
        {
            var result = await _bucket.InsertAsync(Guid.NewGuid().ToString(), message);

            if (!result.Success)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Exemplo n.º 16
0
        public static async Task <string> GetShortUrl(string longUrl)
        {
            // Get new ID
            var id = await _bucket.IncrementAsync(Config.PrimaryKey);

            var res = await _bucket.InsertAsync(id.Value.ToString(), new { url = longUrl });

            if (res.Success)
            {
                return((new ShortUrl((long)id.Value)).ToString());
            }

            if (res.Status == ResponseStatus.KeyExists)
            {
                throw new CouchbaseDuplicateKeyException(res.Message);
            }

            throw new Exception(res.Message);
        }
Exemplo n.º 17
0
        public async Task Create(Person newPerson)
        {
            var doc = new Couchbase.Document <Person>
            {
                Content = newPerson,
                Id      = newPerson.Id
            };

            await peopleBucket.InsertAsync(doc);
        }
        public async Task CreateJobAsync(Job job)
        {
            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }

            job.Id = await GetNextJobIdAsync();

            var document = new Document <Job>
            {
                Id      = Job.GetKey(job.Id),
                Content = job
            };

            var result = await _bucket.InsertAsync(document);

            result.EnsureSuccess();
        }
Exemplo n.º 19
0
        public async Task <Unit> Handle(SocialMediaRequest request, CancellationToken cancellationToken)
        {
            await _bucket.InsertAsync(new Document <SocialMediaUpdateEvent>
            {
                Id      = Guid.NewGuid().ToString(),
                Content = new SocialMediaUpdateEvent(request.socialMedia)
            });

            return(Unit.Value);
        }
Exemplo n.º 20
0
        static async Task <bool> InsertWithPersistTo(Post value)
        {
            var result = await _bucket.InsertAsync(value.PostId, value, ReplicateTo.Zero, Couchbase.PersistTo.Two);

            if (result.Success)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 21
0
        public async Task <ResponseModel <Todo> > CreateOrUpdateTodoAsync(Todo entity)
        {
            try
            {
                if (entity == null)
                {
                    CheckEntity(entity);
                }

                ResponseModel <Todo> response = new ResponseModel <Todo>();
                if (entity.Id == null)
                {
                    entity.Id             = Guid.NewGuid().ToString();
                    entity.CreateDateTime = DateTime.Now;
                    entity.PinnedDateTime = (entity.IsPinned ? DateTime.Now : (DateTime?)null);
                    await todosBucket.InsertAsync(entity.Id, entity);

                    var todoDocument = await todosBucket.GetDocumentAsync <Todo>(entity.Id);

                    response.Entity = todoDocument.Content;
                }
                else
                {
                    var context  = new BucketContext(todosBucket);
                    var category = context.Query <Todo>().FirstOrDefault(u => u.Id == entity.Id);
                    if (category == null)
                    {
                        response.Code    = 0x0005;
                        response.Error   = true;
                        response.Message = "Yapılacak bilgileri eşleşmedi, lütfen tekrar deneyiniz.";
                    }
                    else
                    {
                        var todoDocument = await todosBucket.GetDocumentAsync <Todo>(entity.Id);

                        todoDocument.Content.Title          = entity.Title;
                        todoDocument.Content.Content        = entity.Content;
                        todoDocument.Content.IsPinned       = entity.IsPinned;
                        todoDocument.Content.PinnedDateTime = (entity.IsPinned ? DateTime.Now : (DateTime?)null);
                        todoDocument.Content.Alert          = entity.Alert;
                        todoDocument.Content.IsItDone       = entity.IsItDone;
                        await todosBucket.UpsertAsync(todoDocument.Document);

                        context.SubmitChanges();
                        response.Entity = todoDocument.Content;
                    }
                }
                return(response);
            }
            catch (Exception e)
            {
                return(ThrowingCatch(entity, e));
            }
        }
Exemplo n.º 22
0
 // tag::AddEventsAsync[]
 public async Task AddEventsAsync(List <UserEvent> events)
 {
     var tasks = events.Select(e => _bucket.InsertAsync(e.Id, new
     {
         e.CreatedDate,
         e.EventType,
         e.UserId,
         e.Type
     }));
     await Task.WhenAll(tasks);
 }
Exemplo n.º 23
0
        public async Task <Unit> Handle(StoreMessage request, CancellationToken cancellationToken)
        {
            var message = request.Message;
            await _bucket.InsertAsync(new Document <ChatMessage>
            {
                Id      = Guid.NewGuid().ToString(),
                Content = message
            });

            return(Unit.Value);
        }
Exemplo n.º 24
0
        public async Task <ResponseModel <User> > CreateOrUpdateUserAsync(User entity)
        {
            ResponseModel <User> response = new ResponseModel <User>();

            try
            {
                if (entity == null)
                {
                    CheckEntity(entity);
                }

                if (entity.Id == null)
                {
                    entity.Id             = Guid.NewGuid().ToString();
                    entity.CreateDateTime = DateTime.Now;
                    entity.Password       = Hasher.Hash(entity.Password);
                    await usersBucket.InsertAsync(entity.Id, entity);

                    var userDocument = await usersBucket.GetDocumentAsync <User>(entity.Id);

                    response.Entity = userDocument.Content;
                }
                else
                {
                    var context = new BucketContext(usersBucket);
                    var user    = context.Query <User>().FirstOrDefault(u => u.Id == entity.Id);
                    if (user == null)
                    {
                        response.Code    = 0x0003;
                        response.Error   = true;
                        response.Message = "Kullanıcı bilgileri eşleşmedi, lütfen tekrar deneyiniz.";
                    }
                    else
                    {
                        var userDocument = await usersBucket.GetDocumentAsync <User>(entity.Id);

                        userDocument.Content.NameSurname = entity.NameSurname;
                        userDocument.Content.Username    = entity.Username;
                        userDocument.Content.Password    = Hasher.Hash(entity.Password);
                        await usersBucket.UpsertAsync(userDocument.Document);

                        context.SubmitChanges();
                        response.Entity = userDocument.Content;
                    }
                }

                return(response);
            }
            catch (Exception e)
            {
                return(ThrowingCatch(entity, e));
            }
        }
Exemplo n.º 25
0
        public async Task InsertAsync_DocumentAlreadyExistsException()
        {
            //setup
            var key = "Insert_DocumentAlreadyExistsException";

            _bucket.Remove(new Document <dynamic> {
                Id = key
            });
            _bucket.Insert(new Document <dynamic> {
                Id = key, Content = new { name = "foo" }
            });

            //act
            var result = await _bucket.InsertAsync(new Document <dynamic> {
                Id = key, Content = new { name = "foo" }
            })
                         .ContinueOnAnyContext();

            //assert
            Assert.AreEqual(result.Exception.GetType(), typeof(DocumentAlreadyExistsException));
        }
Exemplo n.º 26
0
        public async Task <IHttpActionResult> Performance(Performance model)
        {
            try
            {
                List <DriverScore> driverScoreList = new List <DriverScore>();
                var         strPath     = @"G:\Projects\APTCAPI\CTAPI\Performance.json";
                string      localPath   = new Uri(strPath).LocalPath;
                Performance performance = new Performance();
                using (StreamReader read = new StreamReader(strPath))
                {
                    string json = read.ReadToEnd();
                    performance = JsonConvert.DeserializeObject <Performance>(json);
                }
                foreach (var score in performance.DriverScore)
                {
                    DriverScore driverScore = new DriverScore();
                    driverScore.DriverId     = score.DriverId;
                    driverScore.KmsTravelled = score.KmsTravelled;
                    driverScore.Braking      = score.Braking;
                    driverScore.Accel        = score.Accel;
                    driverScore.Corner       = score.Corner;
                    driverScore.Idle         = score.Idle;
                    driverScore.Speeding     = score.Speeding;
                    driverScore.AverageTotal = score.Speeding;
                    driverScoreList.Add(score);
                }

                var performanceDoc = new Document <Performance>()
                {
                    Id      = CreateUserKey(),
                    Content = new Performance
                    {
                        //Id = CreateUserKey(),
                        StartDateTime = performance.StartDateTime,
                        EndDateTime   = performance.EndDateTime,
                        Created_On    = DataConversion.ConvertYMDHMS(DateTime.Now.ToString()),
                        DriverScore   = driverScoreList
                    }
                };
                //IBucket _bucketperformance = ClusterHelper.GetBucket("DriverPerfoemance");
                var result = await _bucket.InsertAsync(performanceDoc);

                if (!result.Success)
                {
                    return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), result.Message), new JsonMediaTypeFormatter()));
                }
                return(Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), MessageDescriptions.Add, result.Document.Id), new JsonMediaTypeFormatter()));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter()));
            }
        }
        public async Task CreateCrowdsourcedPoint(CrowdsourcedPlace place)
        {
            place.PlaceId      = Guid.NewGuid();
            place.CreationTime = DateTime.UtcNow;

            var status = await _bucket.InsertAsync(place.PlaceId.ToString(), place).ConfigureAwait(false);

            if (!status.Success)
            {
                throw new ApplicationException(status.Message, status.Exception);
            }
        }
Exemplo n.º 28
0
        public async Task <IHttpActionResult> RegisterLogin(Login model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var modelErrors = new List <string>();
                    foreach (var modelState in ModelState.Values)
                    {
                        foreach (var modelError in modelState.Errors)
                        {
                            modelErrors.Add(modelError.ErrorMessage);
                        }
                    }
                    return(Content(HttpStatusCode.BadRequest, modelErrors[0].ToString()));
                }

                var userKey = "LOGIN_" + model.UserId;
                if (await _bucket.ExistsAsync(userKey))
                {
                    return(Content(HttpStatusCode.Conflict, new Error($"UserId '{model.UserId}' already exists")));
                }
                // call third part api to check Vehicle is valid or not
                var loginDoc = new Document <Login>()
                {
                    Id      = userKey,
                    Content = new Login
                    {
                        Id           = userKey,
                        UserId       = model.UserId,
                        Password     = model.Password,
                        Type         = model.Type,
                        Status       = model.Status,
                        Role         = model.Role,
                        Per_language = model.Per_language,
                        Created_on   = DateTime.Now.Date.ToString()
                    }
                };
                var result = await _bucket.InsertAsync(loginDoc);

                if (!result.Success)
                {
                    return(Content(HttpStatusCode.InternalServerError, new Error(result.Message)));
                }

                return(Content(HttpStatusCode.Accepted, result.Document.Id));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.Forbidden, ex.StackTrace));
            }
        }
Exemplo n.º 29
0
        public async Task <IHttpActionResult> RegisterIncidentMessage(IncidentMessageModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var modelErrors = new List <string>();
                    foreach (var modelState in ModelState.Values)
                    {
                        foreach (var modelError in modelState.Errors)
                        {
                            modelErrors.Add(modelError.ErrorMessage);
                        }
                    }
                    return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), modelErrors[0].ToString()), new JsonMediaTypeFormatter()));
                }

                var userKey = "IncidentMessage_" + model.DriverID + "_" + DateTime.Now.Ticks.ToString();
                //if (await _bucket.ExistsAsync(userKey))
                //{
                //    //return Content(HttpStatusCode.Conflict, new Error($"Incident Message '{model.DriverID}' already exists"));
                //    return Content(HttpStatusCode.Conflict, MessageResponse.Message(HttpStatusCode.Conflict.ToString(), "167-Driver ID already exists"), new JsonMediaTypeFormatter());
                //}
                // call third part api to check Vehicle is valid or not
                var incidentMessageMessageDoc = new Document <IncidentMessageModel>()
                {
                    Id      = userKey,
                    Content = new IncidentMessageModel
                    {
                        DriverID = model.DriverID,
                        DateTime = model.DateTime,
                        Notes    = model.Notes,
                        // this is only UAT testing for check when ct created.
                        Created_On = DataConversion.ConvertYMDHMS(DateTime.Now.ToString()),
                        Created_By = "CarTrack"
                    }
                };
                var result = await _bucket.InsertAsync(incidentMessageMessageDoc);

                if (!result.Success)
                {
                    //return Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), EncryptDecrypt.Encryptword(result.Message)), new JsonMediaTypeFormatter());
                    return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), result.Message), new JsonMediaTypeFormatter()));
                }
                //return Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(),MessageDescriptions.Add, EncryptDecrypt.Encryptword(result.Document.Id)), new JsonMediaTypeFormatter());
                return(Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), MessageDescriptions.Add, result.Document.Id), new JsonMediaTypeFormatter()));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter()));
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Creates a role as an asynchronous operation.
        /// </summary>
        /// <param name="role">The role.</param>
        /// <returns></returns>
        /// <exception cref="CouchbaseException"></exception>
        public async Task CreateAsync(T role)
        {
            var result = await _bucket.InsertAsync(role.Id, role);

            if (!result.Success)
            {
                if (result.Exception != null)
                {
                    throw result.Exception;
                }
                throw new CouchbaseException(result, role.Id);
            }
        }
Exemplo n.º 31
0
 public async Task<string> GetStringAsync(IBucket bucket)
 {
     var doc = "";
     await bucket.InsertAsync("personKey", doc);
     return "someString";
 }