Пример #1
0
 public string CheckPassword(Guid linkId, string password)
 {
     using (var dc = new LinkKSDataContext())
     {
         return(dc.LINKs.Where(c => c.LINK_ID == linkId && c.LINK_PASSWORD == password).Select(c => c.LONG_LINK).FirstOrDefault());
     }
 }
Пример #2
0
 public void UpdateExpireDate(Guid linkId, DateTime?expireDate)
 {
     using (var dc = new LinkKSDataContext())
     {
         var item = dc.LINKs.First(c => c.LINK_ID == linkId);
         item.EXPIRE_DATE = expireDate;
         dc.SubmitChanges();
     }
 }
Пример #3
0
 public void UpdateNotification(Guid linkId, bool notification)
 {
     using (var dc = new LinkKSDataContext())
     {
         var item = dc.LINKs.First(c => c.LINK_ID == linkId);
         item.LINK_NOTIFICATION = notification;
         dc.SubmitChanges();
     }
 }
Пример #4
0
 public void UpdateOneShot(Guid linkId, bool oneshot)
 {
     using (var dc = new LinkKSDataContext())
     {
         var item = dc.LINKs.First((c => c.LINK_ID == linkId));
         item.ONE_SHOT = oneshot;
         dc.SubmitChanges();
     }
 }
Пример #5
0
        //private string GenerateShortLink()
        //{
        //    var rnd = new Random();
        //    var shortLink = "";

        //    for (int i = 0; i < 6; i++)
        //    {
        //        var index = rnd.Next(Link.ValidChars.Length);

        //        shortLink += Link.ValidChars[index];
        //    }

        //    return shortLink;
        //}

        public void UpdatePassword(Guid linkId, string password)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = dc.LINKs.First(c => c.LINK_ID == linkId);
                item.LINK_PASSWORD = password;
                dc.SubmitChanges();
            }
        }
Пример #6
0
 public DTO_USER GetProfile(Guid userId)
 {
     using (var dc = new LinkKSDataContext())
     {
         return(dc.USERs.Where(c => c.USERID == userId).Select(c => new DTO_USER
         {
             Name = c.USERNAME,
             EMail = c.E_MAIL,
             Password = c.USER_PASSWORD
         }).FirstOrDefault());
     }
 }
Пример #7
0
        public void UpdateOneShot(Guid linkId, bool oneShot)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = dc.LINKs.First(c => c.Id == linkId);

                item.OneShot    = oneShot;
                item.UpdateTime = DateTime.Now;

                dc.SubmitChanges();
            }
        }
Пример #8
0
        public void UpdateNotification(Guid linkId, bool notification)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = dc.LINKs.First(c => c.Id == linkId);

                item.Notification = notification;
                item.UpdateTime   = DateTime.Now;

                dc.SubmitChanges();
            }
        }
Пример #9
0
        public void UpdatePassword(Guid linkId, string password)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = dc.LINKs.First(c => c.Id == linkId);

                item.Password   = password;
                item.UpdateTime = DateTime.Now;

                dc.SubmitChanges();
            }
        }
Пример #10
0
        public void UpdateExpireDate(Guid linkId, DateTime?expireDate)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = dc.LINKs.First(c => c.Id == linkId);

                item.ExpireDate = expireDate;
                item.UpdateTime = DateTime.Now;

                dc.SubmitChanges();
            }
        }
Пример #11
0
        public void UpdateProfile(Guid userId, string name, string email, string password)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = dc.USERs.First(c => c.ID == userId);
                item.Name     = name;
                item.EMail    = email;
                item.Password = password;

                dc.SubmitChanges();
            }
        }
Пример #12
0
 public DTO_USER GetProfile(Guid userId)
 {
     using (var dc = new LinkKSDataContext())
     {
         return(dc.USERs.Where(x => x.ID == userId).Select(c => new DTO_USER
         {
             Name = c.Name,
             Email = c.EMail,
             Password = c.Password
         }).FirstOrDefault());
     }
 }
Пример #13
0
 public void UpdateUser(Guid userId, string name, string email, string password)
 {
     using (var dc = new LinkKSDataContext())
     {
         var item = dc.USERs.First(c => c.USERID == userId);
         item.USERNAME      = name;
         item.E_MAIL        = email;
         item.USER_PASSWORD = password;
         item.UPDATE_DATE   = DateTime.Now;
         dc.SubmitChanges();
     }
 }
Пример #14
0
        public Guid?SignIn(string email, string password)
        {
            using (var dc = new LinkKSDataContext())
            {
                var id = dc.USERs.Where(x => x.EMail == email && x.Password == password).Select(c => c.ID).FirstOrDefault();

                if (id == Guid.Empty) // Empty=0
                {
                    return(null);
                }
                return(id);
            }
        }
Пример #15
0
 public Guid?SignIn(string email, string password)
 {
     using (var dc = new LinkKSDataContext())
     {
         //var id = dc.USERs.Where(c => c.E_MAIL == email && c.USER_PASSWORD == password).Select(c => c.USERID).FirstOrDefault();
         var id = (from c in dc.USERs where c.E_MAIL == email select c.USERID).FirstOrDefault();
         if (id == Guid.Empty)
         {
             return(null);
         }
         return(id);
     }
 }
Пример #16
0
 public DTO_LINK_LOG[] ListLog(Guid linkId)
 {
     using (var dc = new LinkKSDataContext())
     {
         return(dc.LINK_LOGs.Where(c => c.LINK_ID == linkId).Select(c => new DTO_LINK_LOG
         {
             IP = c.IP,
             Agent = c.AGENT,
             Date = c.LOG_DATE,
             Referrer = c.REFERRER
         }).ToArray());
     }
 }
Пример #17
0
        public Guid?SignIn(string eMail, string password)
        {
            using (var dc = new LinkKSDataContext())
            {
                var userId = dc.USERs.Where(c => c.EMail == eMail && c.Password == password).Select(c => c.Id).FirstOrDefault();

                if (userId == default(Guid))
                {
                    return(null);
                }

                return(userId);
            }
        }
Пример #18
0
        public void Update(Guid userId, string name, string eMail, string password)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = dc.USERs.Where(c => c.Id == userId).First();

                item.Name       = name;
                item.EMail      = eMail;
                item.Password   = password;
                item.UpdateDate = DateTime.Now;

                dc.SubmitChanges();
            }
        }
Пример #19
0
 public void Log(Guid linkId, string Ip, string Referer, string Agent, DateTime Date)
 {
     using (var dc = new LinkKSDataContext())
     {
         var item = new LINK_LOG();
         item.LOG_ID   = Guid.NewGuid();
         item.IP       = Ip;
         item.LINK_ID  = linkId;
         item.REFERRER = Referer;
         item.AGENT    = Agent;
         item.LOG_DATE = DateTime.Now;
         dc.LINK_LOGs.InsertOnSubmit(item);
         dc.SubmitChanges();
     }
 }
Пример #20
0
        public Guid SignUp(string name, string email, string password)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = new USER();
                item.USERID        = Guid.NewGuid();
                item.USERNAME      = name;
                item.E_MAIL        = email;
                item.USER_PASSWORD = password;
                item.CREATE_DATE   = DateTime.Now;

                dc.USERs.InsertOnSubmit(item);
                dc.SubmitChanges();
                return(item.USERID);
            }
        }
Пример #21
0
        public string GenerateShortLink(LinkKSDataContext dc)
        {
            var rnd = new Random();

            while (true)
            {
                var shortLink = "";
                for (int i = 0; i < 6; i++)
                {
                    var index = rnd.Next(Link.ValidChars.Length);
                    shortLink += Link.ValidChars[index];
                }
                if (!dc.LINKs.Any(c => c.SHORT_LINK == shortLink))
                {
                    return(shortLink);
                }
            }
        }
Пример #22
0
        public Guid SignUp(string name, string email, string password)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = new USER();

                item.ID          = Guid.NewGuid();
                item.Name        = name;
                item.EMail       = email;
                item.Password    = password;
                item.CreatedDate = DateTime.Now;

                dc.USERs.InsertOnSubmit(item);
                dc.SubmitChanges();

                return(item.ID);
            }
        }
Пример #23
0
        //public void UpdateStatus() yazzzzz

        public DTO_LINK[] List(Guid userId)
        {
            using (var dc = new LinkKSDataContext())
            {
                return(dc.LINKs.Where(c => c.USERID == userId).Select(c => new DTO_LINK
                {
                    Id = c.LINK_ID,
                    password = c.LINK_PASSWORD,
                    shortLink = c.SHORT_LINK,
                    longLink = c.LONG_LINK,
                    expiredDate = c.EXPIRE_DATE,
                    oneShot = c.ONE_SHOT,
                    notification = c.LINK_NOTIFICATION,
                    createDateLink = c.CREATE_DATE,
                    STATUS = (Status)c.LINK_STATUS,
                    ClickCount = c.LINK_LOGs.Count
                }).ToArray());
            }
        }
Пример #24
0
 public void Delete(Guid linkId)
 {
     using (var dc = new LinkKSDataContext())
     {
         var item = dc.LINKs.Where(c => c.LINK_ID == linkId).Select(c => c);
         foreach (var i in item)
         {
             dc.LINKs.DeleteOnSubmit(i);
         }
         try
         {
             dc.SubmitChanges();
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #25
0
        public string Shorten(string longLink, Guid?userId, string password)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = new LINK();

                item.ID          = Guid.NewGuid();
                item.LongLink    = longLink;
                item.ShortLink   = this.GenerateShortLink(dc);
                item.UserID      = userId;
                item.Password    = password;
                item.CreatedDate = DateTime.Now;

                dc.LINKs.InsertOnSubmit(item);
                dc.SubmitChanges();

                return(item.ShortLink);
            }
        }
Пример #26
0
        public string Shorten(string longLink, Guid?userId, string password, DateTime?expireDate, bool notification, bool oneshot, byte status)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = new LINK();
                item.LINK_ID           = Guid.NewGuid();
                item.SHORT_LINK        = this.GenerateShortLink(dc);
                item.LONG_LINK         = longLink;
                item.LINK_PASSWORD     = password;
                item.USERID            = userId;
                item.CREATE_DATE       = DateTime.Now;
                item.EXPIRE_DATE       = expireDate;
                item.LINK_NOTIFICATION = notification;
                item.ONE_SHOT          = oneshot;
                item.LINK_STATUS       = status;

                dc.LINKs.InsertOnSubmit(item);
                dc.SubmitChanges();
                return(item.SHORT_LINK);
            }
        }
Пример #27
0
        public string Shorten(string longLink, Guid?userId, string password, DateTime?expireDate, bool oneShot, bool notification)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = new LINK(); //veri tabanında yeni satır oluşturduk

                item.Id           = Guid.NewGuid();
                item.LongLink     = longLink;
                item.ShortLink    = this.GenerateShortLink(dc);
                item.UserId       = userId;
                item.Password     = password;
                item.CreateDate   = DateTime.Now;
                item.OneShot      = oneShot;
                item.Notification = notification;

                dc.LINKs.InsertOnSubmit(item);
                dc.SubmitChanges();

                return(item.ShortLink);
            }
        }
Пример #28
0
        public DTO_LINK_CONTROL_RESULT GetLongLink(string shortLink)
        {
            using (var dc = new LinkKSDataContext())
            {
                var item = dc.LINKs.Where(c => c.SHORT_LINK == shortLink).Select(c => new
                {
                    c.LINK_ID,
                    c.LONG_LINK,
                    c.LINK_STATUS,
                    c.LINK_PASSWORD,
                    c.EXPIRE_DATE,
                    c.ONE_SHOT,
                    clicked = c.LINK_LOGs.Any()
                }).FirstOrDefault();

                if (item == null)
                {
                    return(null);
                }
                if (item.LINK_STATUS != (byte)Status.Active)
                {
                    return(null);
                }
                if (item.EXPIRE_DATE < DateTime.Now)
                {
                    return(null);
                }
                return(new DTO_LINK_CONTROL_RESULT
                {
                    linkId = item.LINK_ID,
                    longLink = item.LONG_LINK,
                    password = item.LINK_PASSWORD != null,
                    oneShot = item.ONE_SHOT && item.clicked
                });
            }
        }