Exemplo n.º 1
0
        public int Post(Models.Favorite value)
        {
            try
            {
                Data.TrnFavorite NewFavorite = new Data.TrnFavorite();

                var userId = (from d in db.MstUsers where d.UserName.Equals(value.User) select d).FirstOrDefault().Id;

                var symbolId = (from d in db.MstSymbols where d.Symbol.Equals(value.Symbol) select d).FirstOrDefault().Id;

                bool isShared = false;
                var  data     = from d in db.TrnFavorites
                                where d.UserId == userId && d.Remarks.Equals(value.Remarks)
                                select d;
                if (data.Any())
                {
                    isShared = data.First().IsShared;
                }

                DateTime    dt          = Convert.ToDateTime(value.EncodedDate);
                SqlDateTime EncodedDate = new SqlDateTime(new DateTime(dt.Year, dt.Month, dt.Day));

                NewFavorite.SymbolId    = symbolId;
                NewFavorite.Symbol      = value.Symbol;
                NewFavorite.Remarks     = value.Remarks;
                NewFavorite.EncodedDate = EncodedDate.Value;
                NewFavorite.Trend       = value.Trend;
                NewFavorite.UserId      = userId;

                NewFavorite.IsShared = isShared;

                db.TrnFavorites.InsertOnSubmit(NewFavorite);
                db.SubmitChanges();

                return(NewFavorite.Id);
            }
            catch
            {
                return(0);
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage Delete(int Id)
        {
            Data.TrnFavorite DeleteFavorite = db.TrnFavorites.Where(d => d.Id == Id).First();

            if (DeleteFavorite != null)
            {
                db.TrnFavorites.DeleteOnSubmit(DeleteFavorite);
                try
                {
                    db.SubmitChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                catch
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }
Exemplo n.º 3
0
        public long GetUploadFavorites([FromUri] List <String> Symbols)
        {
            string currentUserName = User.Identity.Name;
            int    userId          = 0;
            long   returnId        = 0;

            try
            {
                userId = (from d in db.MstUsers where d.UserName.Equals(currentUserName) select d).FirstOrDefault().Id;
                var countFavorites = (from d in db.TrnFavorites where d.UserId == userId select d).Count();

                DateTime now        = DateTime.Now;
                string   uploadDate = now.ToString("yyyy-MM-dd");

                bool isShared = false;
                var  data     = from d in db.TrnFavorites
                                where d.UserId == userId && d.Remarks.Equals("UPLOADED-" + uploadDate)
                                select d;
                if (data.Any())
                {
                    isShared = data.First().IsShared;
                }

                for (int i = 0; i < Symbols.Count; i++)
                {
                    Data.TrnFavorite NewFavorite = new Data.TrnFavorite();

                    var symbolId = from d in db.MstSymbols where d.Symbol.Equals(Symbols[i].Trim()) select d;
                    if (symbolId.Any())
                    {
                        DateTime    d           = DateTime.Now;
                        SqlDateTime EncodedDate = new SqlDateTime(new DateTime(d.Year, d.Month, d.Day));

                        NewFavorite.SymbolId    = symbolId.FirstOrDefault().Id;
                        NewFavorite.Symbol      = Symbols[i].ToUpper();
                        NewFavorite.Remarks     = "UPLOADED-" + uploadDate;
                        NewFavorite.EncodedDate = EncodedDate.Value;
                        NewFavorite.Trend       = "SIDEWAYS";
                        NewFavorite.UserId      = userId;
                        NewFavorite.IsShared    = isShared;

                        db.TrnFavorites.InsertOnSubmit(NewFavorite);
                        db.SubmitChanges();

                        returnId = NewFavorite.Id;
                    }

                    if (currentUserName.ToUpper() != "DPILGER")
                    {
                        if (i > 450 - countFavorites)
                        {
                            break;
                        }
                    }
                }
            }
            catch
            {
            }
            return(returnId);
        }