public bool CreateLot(string ownername, string name, string description, DateTime date, Int64 currency, string typeName, object image) { try { LotDataBase.AddObject(new Lot { Lotname = name, ActualDate = date, Currency = currency, Description = description, IsDeleted = false, OwnerName = ownername, LotType = _dataBase.LotTypes.FirstOrDefault(t => t.TypeName == typeName) }); _dataBase.SaveChanges(); var path = String.Format("{0}Content\\Image\\Lots\\{1}", INITIAL_CATALOG, LotDataBase.FirstOrDefault( t => t.OwnerName == ownername && t.Lotname == name && t.LeaderName == null) .ID); var img = image as HttpPostedFileBase; if (!Directory.Exists(path) && img.ContentLength > 0) { Directory.CreateDirectory(path); img.SaveAs(path + @"\index.jpg"); } else { foreach (var filePath in Directory.GetFiles(path)) { File.Delete(filePath); } } return(true); } catch (Exception) { return(false); } }
public LotModel GetViewModelById(int id) { var lot = LotDataBase.FirstOrDefault(l => l.ID == id); return(lot != null?ConvertToViewModel(lot) : null); }