public bool IsWhouseExists(W_h_info wHInfo)
 {
     try
     {
         string     Query   = "SELECT * FROM tb_WH_Info WHERE (WhName = @WhName and Location = @Location)";
         SqlCommand Command = new SqlCommand(Query, _connection);
         _connection.Open();
         Command.Parameters.Clear();
         Command.Parameters.Add("WhName", SqlDbType.VarChar);
         Command.Parameters["WhName"].Value = wHInfo.WhName;
         Command.Parameters.Add("Location", SqlDbType.VarChar);
         Command.Parameters["Location"].Value = wHInfo.Location;
         SqlDataReader Reader = Command.ExecuteReader();
         Reader.Read();
         bool isExist = Reader.HasRows;
         Reader.Close();
         return(isExist);
     }
     catch (Exception exception)
     {
         throw new Exception("Unable to connect Server", exception);
     }
     finally
     {
         _connection.Close();
     }
 }
        public int SaveWhouse(W_h_info wHInfo)
        {
            string query = @"INSERT INTO [dbo].[tb_WH_Info]
           ([WhName]
           ,[Location]
           ,[Capacity]
           ,[EmployeeId])
     VALUES
           ('" + wHInfo.WhName + "', '" + wHInfo.Location + "', '" + wHInfo.Capacity + "', '" + wHInfo.EmployeeId + "')";

            try
            {
                SqlCommand command = new SqlCommand(query, _connection);
                _connection.Open();
                int rowAffected = command.ExecuteNonQuery();
                _connection.Close();

                return(rowAffected);
            }
            catch (Exception exception)
            {
                throw new Exception("Unable to connect Server", exception);
            }
            finally
            {
                _connection.Close();
            }
        }
        public HttpResponseMessage PostWhouse(W_h_info wHInfo)
        {
            var messages = _whouseinfo.SaveWhouse(wHInfo);

            if (messages != null)
            {
                var message = Request.CreateResponse(HttpStatusCode.Created, messages);
                return(message);
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Category not created"));
        }
Ejemplo n.º 4
0
        public string SaveWhouse(W_h_info wHInfo)
        {
            if (_whouseinfo.IsWhouseExists(wHInfo))
            {
                return("W H Name Already Exists.");
            }
            if (_whouseinfo.SaveWhouse(wHInfo) > 0)
            {
                return("W H Name Saved Successfully");
            }

            return("W H Name Save Faild");
        }
        public ActionResult SaveWhouse(W_h_info wHInfo)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    ViewBag.ShowMsg = _whouseinfo.SaveWhouse(wHInfo);
                }
                catch (Exception exception)
                {
                    ViewBag.ShowMsg = exception.Message;
                }
            }
            ViewBag.employees = _shopInfo.GetAllEmployees();

            return(View());
        }
        public ActionResult SaveWhouse(W_h_info wHInfo)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:32331");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var response = client.PostAsJsonAsync("api/Whouse/PostWhouse", wHInfo).Result;

                if (response.IsSuccessStatusCode)
                {
                    string msg     = response.Content.ReadAsStringAsync().Result;
                    var    records = JsonConvert.DeserializeObject(msg); //  JSON.Net
                    ViewBag.ShowMsg = records;
                }
            }
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:32331");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = client.GetAsync("api/Whouse/").Result;
                string res = "";
                using (HttpContent content = response.Content)
                {
                    // ... Read the string.
                    Task <string> result = content.ReadAsStringAsync();
                    res = result.Result;

                    var records = JsonConvert.DeserializeObject <List <Employee> >(res); //  JSON.Net

                    foreach (Employee record in records)
                    {
                        var category = (string.Format("Id: {0}, EmployeeName: {1}", record.Id, record.EmployeeName));
                    }

                    ViewBag.employees = records;
                }
            }

            return(View());
        }