简体   繁体   中英

Creating Web API Using Azure SQL Server

I tried this tutorial for my xamarin app, with this code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace XamarinLogin.Controllers
{
    public class ControllerNameController : ApiController
    {
        // GET: api/ControllerName
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/ControllerName/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/ControllerName
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/ControllerName/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/ControllerName/5
        public void Delete(int id)
        {
        }
         xamarinloginEntities db = new xamarinloginEntities();  

        [HttpPost]  
        [ActionName("XAMARIN_REG")]  
        // POST: api/Login  
        public HttpResponseMessage Xamarin_reg(string username, string password)  
        {  
            Login login = new Login();  
            login.Username = username;  
            login.Password = password;  
            db.Logins.Add(login);  
            db.SaveChanges();  
            return Request.CreateResponse(HttpStatusCode.Accepted, "Successfully Created");  
        }  
        [HttpGet]  
        [ActionName("XAMARIN_Login")]  
        // GET: api/Login/5  
        public HttpResponseMessage Xamarin_login(string username, string password)  
        {  
            var user = db.Logins.Where(x => x.Username == username && x.Password == password).FirstOrDefault();  
            if (user == null)  
            {  
                return Request.CreateResponse(HttpStatusCode.Unauthorized, "Please Enter valid UserName and Password");  
            }  
            else  
            {  
                return Request.CreateResponse(HttpStatusCode.Accepted, "Success");  
            }  
        }  

    }
}

I'm already following exactly like the tutorial but I still got an error message, and this is the error message,

The type or namespace name xamarinloginentities could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name Login could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name xamarinloginentities could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name Login could not be found (are you missing a using directive or an assembly reference?)

as you can see Login and xamarinloginentities is my ADO.NET Entity Data Model the question is how can I get this error message.

The type or namespace name xamarinloginentities could not be found (are you missing a using directive or an assembly reference?)

Per my understanding, the class name (eg xamarinloginEntities ) need to be case sensitive. Additionally, if you follow the tutorial you provided, the ASP.NET Entity Data Model would be defined under your Project Name -> Models , for your ControllerNameController.cs , you need to add the namespace reference as follows:

using XamarinLogin.Models;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM