private string SaveFile(HttpPostedFileBase file, string folder, string old_file = null)
{
int typeBegin = file.FileName.LastIndexOf('.');
string fileType = file.FileName.Substring(typeBegin, file.FileName.Length - typeBegin);
//генерируем уникальное имя
var fileName = Security.GetMd5(User.Identity.GetUserId() + DateTime.Now.ToFileTimeUtc()) + fileType;
var path = Path.Combine(Server.MapPath(folder), fileName);
file.SaveAs(path);
if (old_file != null && old_file != "/Content/images/default-dish.png")
{
path = Server.MapPath(old_file);
FileInfo fi = new FileInfo(path);
try
{
fi.Delete();
}
catch { }
}
return fileName;
}