public Models.UserFavorite GetUserFavorite(String Id)
        {
            Models.UserFavorite userFavorites = new Models.UserFavorite();

            try
            {
                var data = from d in db.TrnUserFavorites
                           where d.Id == Convert.ToInt32(Id)
                           select new Models.UserFavorite
                {
                    Id          = d.Id,
                    UserId      = d.UserId,
                    User        = d.MstUser.UserName,
                    Description = d.Description,
                    IsShared    = d.IsShared,
                    EncodedDate = d.EncodedDate.HasValue ? Convert.ToString(d.EncodedDate.Value.Year) + "-" + Convert.ToString(d.EncodedDate.Value.Month + 100).Substring(1, 2) + "-" + Convert.ToString(d.EncodedDate.Value.Day + 100).Substring(1, 2) : "NA"
                };

                userFavorites = data.FirstOrDefault();
            }
            catch
            {
                userFavorites = new Models.UserFavorite();
            }

            return(userFavorites);
        }
        public int Post(Models.UserFavorite value)
        {
            try
            {
                Data.TrnUserFavorite newUserFavorite = new Data.TrnUserFavorite();

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

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

                newUserFavorite.UserId      = userId;
                newUserFavorite.Description = value.Description;
                newUserFavorite.IsShared    = isShared;
                newUserFavorite.EncodedDate = EncodedDate.Value;

                db.TrnUserFavorites.InsertOnSubmit(newUserFavorite);
                db.SubmitChanges();

                return(newUserFavorite.Id);
            }
            catch
            {
                return(0);
            }
        }
        public HttpResponseMessage Put(String Id, Models.UserFavorite value)
        {
            Id = Id.Replace(",", "");
            int id = Convert.ToInt32(Id);

            try
            {
                var userFavorites = from d in db.TrnUserFavorites where d.Id == id select d;

                if (userFavorites.Any())
                {
                    var updatedUserFavorites = userFavorites.FirstOrDefault();

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

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

                    updatedUserFavorites.UserId      = userId;
                    updatedUserFavorites.Description = value.Description;
                    updatedUserFavorites.IsShared    = value.IsShared;
                    updatedUserFavorites.EncodedDate = EncodedDate.Value;

                    db.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch (NullReferenceException)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }