Skip to content

Instantly share code, notes, and snippets.

public class CollectionViewModel
{
public int? Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool Published { get; set; }
public HttpPostedFileBase ThumbnailFile { get; set; }
}
@Boztown
Boztown / ImageProcessingUtility.cs
Last active July 19, 2019 10:47
Here's a little function in C# to resize an image with proportional constraints. Just specific the max width and max height and this method will return a bitmap all sized up for you. I have this snipped in the form of a static **Utilities** class because that's how I use it.
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Drawing;
namespace Utilities
{
// if our viewmodel has an ID then grab that entity... otherwise create a new one
var collection = collectionDto.Id.HasValue ? _collectionRepository.Get(collectionDto.Id.Value) : new Collection();
public int Save(CollectionViewModel collectionModel)
{
var collection = collectionModel.Id.HasValue ? _collectionRepository.Get(collectionModel.Id.Value) : new Collection();
collection.Name = collectionModel.Name;
collection.Published = collectionModel.Published;
collection.Featured = collectionModel.Featured;
collection.Description = collectionModel.Description;
_collectionRepository.Save(collection);
return collection.Id;
[HttpPost]
public ActionResult Edit(CollectionViewModel model)
{
if (ModelState.IsValid)
{
var id = _collectionModel.Save(model);
}
return View(model);
}
@model ViewModels.CollectionViewModel
@{
string actionKeyword = ViewData["ActionKeyword"].ToString();
}
@using (Html.BeginForm("edit", "collection", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<label class="control-label">Name:</label>
@model ViewModels.CollectionViewModel
@{
Layout = “~/Views/Shared/Layout.cshtml”;
}
@section AdditionalHeadContent {
<script>
$(document).ready(function () {});
@Boztown
Boztown / gist:7740769
Created December 1, 2013 21:05
Wordpress: Delete attachments after a custom post type is deleted.
function handle_delete_listing( $post_id )
{
$cargs = array(
'post_type' => 'attachment',
'post_parent' => $post_id
);
$attachments = get_children($cargs);
if ($attachments) {