public static int RemoveBin(int binID) { BinModel data = new BinModel { BinID = binID }; string sql = @"delete from dbo.bins WHERE BinID = @BinID;"; return(SqlDataAccess.Execute(sql, data)); }
public async Task <IHttpActionResult> AddBin(BinModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } model.Id = Guid.NewGuid(); Utils.ExecuteNonQuery(SQLCommands.AddBin(model)); return(Ok()); }
public ActionResult DeleteBin(BinModel model) { try { RemoveBin(model.BinID); return(RedirectToAction("Index")); } catch (Exception e) { TempData["errorMessage"] = "That operation could not be completed. Please update the information and try again, or contact your system administrator."; return(RedirectToAction("Index")); } }
public static int CreateBin(int binID, string binName) { BinModel data = new BinModel { BinID = binID, BinName = binName }; string sql = @"insert into dbo.bins (BinName) values (@BinName);"; return(SqlDataAccess.Execute(sql, data)); }
public static int UpdateBin(int binID, string binName) { BinModel data = new BinModel { BinID = binID, BinName = binName }; string sql = @"update dbo.bins set BinName = @BinName WHERE BinID = @BinID;"; return(SqlDataAccess.Execute(sql, data)); }
public static SqlCommand AddBin(BinModel model) { SqlCommand cmd = new SqlCommand(); string str = "insert into [dbo].[Bins] (Id, Name, Type, Latitude, Longitude, Capacity, Zone) values (@mId, @mName, @mType, @mLatitude, @mLongitude, @mCapacity, @mZone)"; cmd.CommandText = str; cmd.Parameters.Add("@mId", SqlDbType.UniqueIdentifier).Value = model.Id; cmd.Parameters.Add("@mName", SqlDbType.NVarChar).Value = model.Name; cmd.Parameters.Add("@mType", SqlDbType.Int).Value = model.Type; cmd.Parameters.Add("@mLatitude", SqlDbType.Float).Value = model.Latitude; cmd.Parameters.Add("@mLongitude", SqlDbType.Float).Value = model.Longitude; cmd.Parameters.Add("@mCapacity", SqlDbType.Float).Value = model.Capacity; cmd.Parameters.Add("@mZone", SqlDbType.Int).Value = model.Zone; return(cmd); }
public ActionResult EditBin(BinModel model) { if (ModelState.IsValid) { try { UpdateBin(model.BinID, model.BinName); return(RedirectToAction("Index")); } catch (Exception e) { ViewBag.ErrorMessage = "That operation could not be completed. Please update the information and try again, or contact your system administrator."; return(View(model)); } } return(View()); }
public async Task <IHttpActionResult> GetBin(Guid Id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DataTable dt = Utils.ExecuteTable(SQLCommands.GetBin(Id)); BinModel bin = Utils.DataTableToList <BinModel>(dt)[0]; if (dt.Rows.Count == 0) { return(NotFound()); } else { return(Ok(bin)); } }