Beispiel #1
0
        public ActionResult <DeveloperResponse> Update([FromBody] Developer data)
        {
            try
            {
                //check if email is present
                if (string.IsNullOrWhiteSpace(data.Email))
                {
                    return(BadRequest(new { Message = Constants.Provide_Email }));
                }

                //check if email is present
                if (string.IsNullOrWhiteSpace(data.Phone_Number))
                {
                    return(BadRequest(new { Message = Constants.Provide_Phone }));
                }
                data.Email = data.Email.ToLower();
                //Check for email formats
                if (!Checks.IsValidEmail(data.Email))
                {
                    return(BadRequest(new { Message = Constants.Invalid_Email }));
                }
                //check if a guid is included in the data
                if (string.IsNullOrWhiteSpace(data.Guid))
                {
                    return(BadRequest(new { Message = Constants.Provide_Guid }));
                }

                //check if the developer exists on the system via guid.

                if (!Store.CheckTestExistence(e => e.Guid, data.Guid))
                {
                    return(NotFound(new { Message = Constants.Non_Exist }));
                }

                //Update the Contact
                MongoDB.Driver.IMongoQuery query = Query <Developer> .EQ(d => d.Guid, data.Guid);

                MongoDB.Driver.IMongoUpdate replacement = Update <Developer> .Replace(data);

                context.Developer.Update(query, replacement);

                //initialize response data.
                DeveloperResponse response = new DeveloperResponse
                {
                    //prepare response data
                    Status  = true,
                    Message = Constants.Success,

                    //return the newly inserted data from the database.
                    Data = Store.FetchTestOne(d => d.Email, data.Email)
                };
                return(Ok(response));
            }
            catch (Exception ex)
            {
                Log.LogError(ex);
                return(StatusCode(500, ex.ToString()));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="collectionName">集合名称</param>
        /// <param name="query">查询条件条件查询,调用示例:Query.Matches("Title", "感冒") 或者 Query.EQ("Title", "感冒") 或者Query.And(Query.Matches("Title", "感冒"),Query.EQ("Author", "yanc")) 等等</param>
        /// <param name="update">更新字段,调用示例:Update.Set("Title", "yanc") 或者 Update.Set("Title", "yanc").Set("Author", "yanc2") 等等</param>
        public static bool Update(string collectionName, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoUpdate update)
        {
            var result = MongoDbHepler.Update(nosqlConnectionString, nosqlDbName, collectionName, query, update);

            return(result.Ok);
        }