internal string createFavoriteStock(string code, int operId) { int status = 0; using (var db = new WebStockEntities()) { var check = db.stockIndex.Where(x => (x.code == code || x.company == code) && x.isEnable == true).FirstOrDefault(); if (check != null) { var r = db.stockFavorite.Where(x => x.operId == operId && x.code == check.code).FirstOrDefault(); if (r == null) { stockFavorite data = new stockFavorite(); data.operId = operId; data.code = check.code; db.stockFavorite.Add(data); status = db.SaveChanges(); return(status > 0 ? "01" : "02"); } else { //已存在無須新增 return("03"); } } else { return("02"); } } }
internal string addFavorite(string code, int OperId) { using (var db = new WebStockEntities()) { stockFavorite favorite = new stockFavorite(); favorite.operId = OperId; favorite.code = code; db.stockFavorite.Add(favorite); db.SaveChanges(); return("success"); } }
internal bool updateFavoriteStockMemo(stockFavorite favorite) { int status = 0; using (var db = new WebStockEntities()) { var d = db.stockFavorite.Where(x => x.id == favorite.id).FirstOrDefault(); Mapper.Initialize(cfg => cfg.CreateMap <stockFavorite, stockFavorite>() .ForMember(x => x.id, opt => opt.Ignore()) .ForMember(x => x.operId, opt => opt.Ignore()) .ForMember(x => x.code, opt => opt.Ignore()) ); Mapper.Map(favorite, d); status = db.SaveChanges(); } return(status >= 0 ? true : false); }