public void DeletePetAnimal(PetAnimal animal) { if (animal == null) { throw new ArgumentNullException("animal"); } using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString)) { connection.Open(); var command = new SqlCommand("usp_DeletePetAnimal", connection) { CommandType = System.Data.CommandType.StoredProcedure }; command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@ID", SqlDbType = SqlDbType.UniqueIdentifier, SqlValue = animal.ID }); command.ExecuteNonQuery(); } }
public void DeletePetAnimal(PetAnimal animal) { if (animal == null) throw new ArgumentNullException("animal"); using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString)) { connection.Open(); var command = new SqlCommand("usp_DeletePetAnimal", connection) { CommandType = System.Data.CommandType.StoredProcedure }; command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@ID", SqlDbType = SqlDbType.UniqueIdentifier, SqlValue = animal.ID }); command.ExecuteNonQuery(); } }
public async Task <ActionResult> Create([Bind(Include = "Id,Name,ShortCode,Age,Color,ImageUrl,Quantity,Details,Price,PhoneNumber,Email,IsSold,Area,City,Division,PetTypeID,PetTypeName,CreateBy,CreateDate")] PetAnimal petAnimal, HttpPostedFileBase file) { if (ModelState.IsValid) { try { String fileName = ""; if (file != null) { fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); string physicalPath = Server.MapPath("~/Images/PetImage/" + fileName); file.SaveAs(physicalPath); petAnimal.ImageUrl = @"~/" + @"Images/PetImage" + @"/" + fileName; } petAnimal.CreateBy = User.Identity.GetUserId(); ViewBag.FileStatus = "File uploaded successfully."; petAnimal.CreateDate = DateTime.Now; petAnimal.ShortCode = "Pet" + Guid.NewGuid().ToString(); db.PetAnimal.Add(petAnimal); await db.SaveChangesAsync(); } catch (Exception) { ViewBag.FileStatus = "Error while file uploading."; } //db.PetAnimal.Add(petAnimal); //await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.PetTypeID = new SelectList(db.PetType, "PetTypeID", "PetTypeName", petAnimal.PetTypeID); return(View(petAnimal)); }
public async Task <ActionResult> DeleteConfirmed(int id) { PetAnimal petAnimal = await db.PetAnimal.FindAsync(id); db.PetAnimal.Remove(petAnimal); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public delegate void PetAnimal(string pet); // Create delegate public static void CallAnonymous() { PetAnimal petAnimal = delegate(string petName) { Console.WriteLine(petName); }; petAnimal("Hello"); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,ShortCode,Age,Color,ImageUrl,Quantity,Details,Price,PhoneNumber,Email,IsSold,Area,City,Division,PetTypeID,PetTypeName,CreateBy,CreateDate")] PetAnimal petAnimal) { if (ModelState.IsValid) { db.Entry(petAnimal).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.PetTypeID = new SelectList(db.PetType, "PetTypeID", "PetTypeName", petAnimal.PetTypeID); return(View(petAnimal)); }
public async Task <ActionResult> Details(int?id) { ViewBag.Current = "PetAnimals"; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PetAnimal petAnimal = await db.PetAnimal.FindAsync(id); if (petAnimal == null) { return(HttpNotFound()); } return(View(petAnimal)); }
public async Task <ActionResult> Edit(int?id) { ViewBag.Current = "PetAnimals"; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PetAnimal petAnimal = await db.PetAnimal.FindAsync(id); if (petAnimal == null) { return(HttpNotFound()); } ViewBag.PetTypeID = new SelectList(db.PetType, "PetTypeID", "PetTypeName", petAnimal.PetTypeID); return(View(petAnimal)); }
public void UpdatePetAnimal(PetAnimal animal) { if (animal == null) { throw new ArgumentNullException("animal"); } using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString)) { connection.Open(); var command = new SqlCommand("usp_UpdatePetAnimal", connection) { CommandType = System.Data.CommandType.StoredProcedure }; FillCommand(command, animal); command.ExecuteNonQuery(); } }
public async Task <ActionResult> Index() { PetAnimal petAnimals = new PetAnimal(); ViewBag.Current = "PetAnimals"; //if (User.Identity.GetUserId() == petAnimals.CreateBy) //{ // var petAnimal = db.PetAnimal.Include(p => p.PetType); // return View(await petAnimal.ToListAsync()); // //return View(db.PetAnimal.Where(x => x.CreateBy.Equals(User.Identity.GetUserId())).ToList()); //} //return View(); var getUserID = User.Identity.GetUserId(); var adminID = "6123524f-662d-4677-8836-5c95da5e52c8"; var petAnimal = db.PetAnimal.Include(p => p.PetType); if (getUserID.Equals(adminID)) { return(View(await petAnimal.ToListAsync())); } return(View(await petAnimal.Where(x => x.CreateBy.Equals(getUserID)).ToListAsync())); }
internal void InsertPetAnimal(PetAnimal animal) { container.Resolve<IPetMatchRepository>().InsertPetAnimal(animal); }
internal void DeletePetAnimal(PetAnimal animal) { container.Resolve<IPetMatchRepository>().DeletePetAnimal(animal); }
private void FillCommand(SqlCommand command, PetAnimal animal) { command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = false, ParameterName = "@ID", SqlDbType = SqlDbType.UniqueIdentifier, SqlValue = animal.ID }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = false, ParameterName = "@Name", SqlDbType = SqlDbType.NVarChar, Size = 100, SqlValue = animal.Name }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@DateCreated", SqlDbType = SqlDbType.DateTime, SqlValue = animal.DateCreated }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@CreatedBy", SqlDbType = SqlDbType.NVarChar, Size = 512, SqlValue = animal.CreatedBy }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@LastUpdated", SqlDbType = SqlDbType.DateTime, SqlValue = animal.LastUpdated }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@LastUpdatedBy", SqlDbType = SqlDbType.NVarChar, Size = 512, SqlValue = animal.LastUpdatedBy }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = false, ParameterName = "@Visible", SqlDbType = SqlDbType.Bit, SqlValue = animal.Visible }); }
public void UpdatePetAnimal(PetAnimal animal) { if (animal == null) throw new ArgumentNullException("animal"); using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString)) { connection.Open(); var command = new SqlCommand("usp_UpdatePetAnimal", connection) { CommandType = System.Data.CommandType.StoredProcedure }; FillCommand(command, animal); command.ExecuteNonQuery(); } }
private void FillCommand(SqlCommand command, PetAnimal animal) { command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = false, ParameterName = "@ID", SqlDbType = SqlDbType.UniqueIdentifier, SqlValue = animal.ID }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = false, ParameterName = "@Name", SqlDbType = SqlDbType.NVarChar, Size = 100, SqlValue = animal.Name }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@DateCreated", SqlDbType = SqlDbType.DateTime, SqlValue = animal.DateCreated }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@CreatedBy", SqlDbType = SqlDbType.NVarChar, Size = 512, SqlValue = animal.CreatedBy }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@LastUpdated", SqlDbType = SqlDbType.DateTime, SqlValue = animal.LastUpdated }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = true, ParameterName = "@LastUpdatedBy", SqlDbType = SqlDbType.NVarChar, Size = 512, SqlValue = animal.LastUpdatedBy }); command.Parameters.Add(new SqlParameter { Direction = ParameterDirection.Input, IsNullable = false, ParameterName = "@Visible", SqlDbType = SqlDbType.Bit, SqlValue = animal.Visible }); }