public bool MakeBet(int lotid, string leadername, Int64 newcurrency) { try { var lot = LotDataBase.First(t => t.ID == lotid); lot.Currency = newcurrency; lot.LeaderName = leadername; _dataBase.SaveChanges(); return(true); } catch (Exception) { return(false); } }
internal IEnumerable <LotModel> GetLotTypePreviewCollection(string typeName) { var rnd = new Random(); int count; if ((count = (LotDataBase.Count(t => !t.IsDeleted && t.LotType.TypeName == typeName) >= 3)?3:LotDataBase.Count(t => !t.IsDeleted && t.LotType.TypeName == typeName)) > 0) { for (var i = 0; i < count; i++) { var index = rnd.Next(LotDataBase.Count(t => !t.IsDeleted && t.LotType.TypeName == typeName)); yield return (ConvertToViewModel(LotDataBase.Where(t => !t.IsDeleted && t.LotType.TypeName == typeName).ToList()[index])); _dataBase.Lots.Remove(LotDataBase.Where(t => !t.IsDeleted && t.LotType.TypeName == typeName).ToList()[index]); } } }
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); }