Example #1
0
        /// <summary>
        /// Get next point.
        /// </summary>
        public static MsPoint GetNextPoint(BrickNode[,] sudokuint, MsPoint point)
        {
            MsPoint newPoint = new MsPoint()
            {
                X = point.X, Y = point.Y
            };

            if (newPoint.X == 8 && newPoint.Y == 8)
            {
                return(newPoint);
            }

            if (newPoint.Y == 8)
            {
                newPoint.X++;
                newPoint.Y = 0;
            }
            else
            {
                newPoint.Y++;
            }

            if (sudokuint[newPoint.X, newPoint.Y].Kind == BrickKind.Original)
            {
                return(Sudoku.GetNextPoint(sudokuint, newPoint));
            }
            else
            {
                return(newPoint);
            }
        }
Example #2
0
        /// <summary>
        /// Get available BrickNodes with known x and y for sudoku.
        /// </summary>
        /// <returns></returns>
        public static List <BrickNode> GetAvailableBrickNodes(BrickNode[,] sudoku, MsPoint point)
        {
            List <BrickNode> availableBrickNodes = new List <BrickNode>();

            if (sudoku == null || sudoku[point.X, point.Y].Kind == BrickKind.Original)
            {
                return(availableBrickNodes);
            }

            List <int> numbers = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };

            for (int i = 0; i <= 8; i++)
            {
                if (numbers.Contains(sudoku[i, point.Y].Number))
                {
                    numbers.Remove(sudoku[i, point.Y].Number);
                }
            }

            for (int i = 0; i <= 8; i++)
            {
                if (numbers.Contains(sudoku[point.X, i].Number))
                {
                    numbers.Remove(sudoku[point.X, i].Number);
                }
            }

            int minX = (point.X / 3) * 3, minY = (point.Y / 3) * 3;

            for (int i = minX; i <= minX + 2; i++)
            {
                for (int j = minY; j <= minY + 2; j++)
                {
                    if (numbers.Contains(sudoku[i, j].Number))
                    {
                        numbers.Remove(sudoku[i, j].Number);
                    }
                }
            }

            foreach (int number in numbers)
            {
                availableBrickNodes.Add(new BrickNode {
                    Number = number, Kind = BrickKind.General
                });
            }

            return(availableBrickNodes);
        }
Example #3
0
        /// <summary>
        /// Process for calculating.
        /// </summary>
        private void Calculating(BrickNode[,] sudokuParam, MsPoint point)
        {
            if (this.GotAnswer || this.Stop)
            {
                return;
            }

            this.CalculateCount++;

            BrickNode[,] sudoku = sudokuParam.Clone() as BrickNode[, ];

            if (point.X == 8 && point.Y == 8 && sudoku[point.X, point.Y].Number != 0)
            {
                this.Answer    = sudoku;
                this.GotAnswer = true;

                return;
            }

            if (sudoku[point.X, point.Y].Kind == BrickKind.Original)
            {
                this.Calculating(sudoku, Sudoku.GetNextPoint(sudoku, point));
            }
            else
            {
                List <BrickNode> BrickNodes = Sudoku.GetAvailableBrickNodes(sudoku, point);

                if (BrickNodes.Count == 0)
                {
                    return;
                }

                foreach (BrickNode BrickNode in BrickNodes)
                {
                    sudoku[point.X, point.Y] = BrickNode;

                    if (point.X == 8 && point.Y == 8 && sudoku[8, 8].Number != 0)
                    {
                        this.Answer    = sudoku;
                        this.GotAnswer = true;

                        return;
                    }
                    //Debug.WriteLine(point.X + "," + point.Y + "  " + BrickNode.Number);
                    this.Calculating(sudoku, Sudoku.GetNextPoint(sudoku, point));
                }
            }
        }
        // POST api/values
        public object Post()
        {
            JsonResultViewModel result = new JsonResultViewModel();

            result.status      = true;
            result.message     = "Comment successfully updated";
            result.messageCode = "S";

            var    httpRequest   = HttpContext.Current.Request;
            long   id            = string.IsNullOrEmpty(httpRequest["Id"]) ? 0 : long.Parse(httpRequest["Id"]);
            long   articleId     = string.IsNullOrEmpty(httpRequest["ArticleId"]) ? 0 : long.Parse(httpRequest["ArticleId"]);
            string postedComment = httpRequest["Comment"];
            string userId        = httpRequest["userId"];


            try
            {
                using (PatuhEntities db = new PatuhEntities())
                {
                    TrComment comment = db.TrComments.Where(x => x.Id == id).FirstOrDefault();

                    if (comment == null)
                    {
                        comment          = new TrComment();
                        comment.cCreated = userId;
                        comment.dCreated = DateTime.Now;
                        db.TrComments.AddObject(comment);

                        MsPoint msPoint = db.MsPoints.Where(x => x.ActionCode == "COMMENTART").FirstOrDefault();

                        if (msPoint != null)
                        {
                            TrArticle trArticle = db.TrArticles.Where(x => x.Id == articleId).FirstOrDefault();

                            if (trArticle != null)
                            {
                                TrPoint trPoint = new TrPoint();

                                trPoint.ArticleId    = trArticle.Id;
                                trPoint.UserID       = trArticle.cCreated;
                                trPoint.ActionCode   = "COMMENTART";
                                trPoint.PointValue   = msPoint.RewardPoint;
                                trPoint.cCreated     = userId;
                                trPoint.dCreated     = DateTime.Now;
                                trPoint.cLastUpdated = userId;
                                trPoint.dLastUpdated = DateTime.Now;

                                db.TrPoints.AddObject(trPoint);
                                //db.SaveChanges();
                            }
                        }
                    }



                    comment.ArticleId = articleId;
                    comment.Comment   = postedComment;

                    comment.cLastUpdated = userId;
                    comment.dLastUpdated = DateTime.Now;

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result.status      = false;
                result.message     = e.Message;
                result.messageCode = "Error in saving Comment";
            }

            return(result);
        }
        // POST api/values
        public object Post()
        {
            JsonResultViewModel result = new JsonResultViewModel();

            result.status      = true;
            result.message     = "Article successfully updated";
            result.messageCode = "S";

            var    httpRequest = HttpContext.Current.Request;
            long   id          = string.IsNullOrEmpty(httpRequest["Id"]) ? 0 : long.Parse(httpRequest["Id"]);
            string title       = httpRequest["title"];
            string story       = httpRequest["story"];
            string location    = httpRequest["location"];
            double latitude    = string.IsNullOrEmpty(httpRequest["latitude"]) ? 0 : double.Parse(httpRequest["latitude"]);
            double longitude   = string.IsNullOrEmpty(httpRequest["longitude"]) ? 0 : double.Parse(httpRequest["longitude"]);
            string userId      = httpRequest["userId"];


            try
            {
                using (PatuhEntities db = new PatuhEntities())
                {
                    TrArticle article = db.TrArticles.Where(x => x.Id == id).FirstOrDefault();

                    if (article == null)
                    {
                        article          = new TrArticle();
                        article.cCreated = userId;
                        article.dCreated = DateTime.Now;
                        db.TrArticles.AddObject(article);
                    }


                    article.Category    = "ARTICLE";
                    article.Title       = title;
                    article.Story       = story;
                    article.GPSLocation = location;
                    article.GPSLong     = longitude;
                    article.GPSLat      = latitude;

                    article.cLastUpdated = userId;
                    article.dLastUpdated = DateTime.Now;

                    db.SaveChanges();

                    try
                    {
                        if (httpRequest.Files.Count > 0)
                        {
                            IList <TrImageAttachment> currentImages = db.TrImageAttachments.Where(x => x.HeaderId == article.Id).ToList();
                            if (currentImages != null && currentImages.Count > 0)
                            {
                                foreach (TrImageAttachment dbImg in currentImages)
                                {
                                    db.TrImageAttachments.DeleteObject(dbImg);
                                }
                            }

                            string extention = "";
                            string guid      = "";

                            string[] supportedTypes = new string[] { "jpg", "jpeg", "bmp", "png" };
                            int      fileSequence   = 0;

                            foreach (string file in httpRequest.Files)
                            {
                                var  postedFile = httpRequest.Files[file];
                                Type fileType   = postedFile.GetType();
                                if (postedFile != null)
                                {
                                    if (postedFile.FileName != "")
                                    {
                                        byte[] theImage = new byte[postedFile.ContentLength];
                                        extention = (Path.GetExtension(postedFile.FileName).TrimStart('.')).ToLower();

                                        if (supportedTypes.Contains(extention))
                                        {
                                            postedFile.InputStream.Read(theImage, 0, postedFile.ContentLength);


                                            TrImageAttachment imageAtt = new TrImageAttachment();// db.TrImageAttachments.Where(x => x.Id == id).FirstOrDefault();


                                            imageAtt          = new TrImageAttachment();
                                            imageAtt.HeaderId = article.Id;

                                            imageAtt.cCreated = userId;
                                            imageAtt.dCreated = DateTime.Now;

                                            imageAtt.Sequence     = ++fileSequence;
                                            imageAtt.Image        = theImage;
                                            imageAtt.cLastUpdated = userId;
                                            imageAtt.dLastUpdated = DateTime.Now;

                                            db.TrImageAttachments.AddObject(imageAtt);
                                            db.SaveChanges();
                                        }
                                    }
                                }
                            }
                        }//

                        // incerement points earned by user's creating the article

                        if (id == 0)
                        {
                            MsPoint msPoint = db.MsPoints.Where(x => x.ActionCode == "CREATEART").FirstOrDefault();

                            if (msPoint != null)
                            {
                                TrPoint trPoint = new TrPoint();

                                trPoint.ArticleId    = article.Id;
                                trPoint.UserID       = article.cCreated;
                                trPoint.ActionCode   = "CREATEART";
                                trPoint.PointValue   = msPoint.RewardPoint;
                                trPoint.cCreated     = userId;
                                trPoint.dCreated     = DateTime.Now;
                                trPoint.cLastUpdated = userId;
                                trPoint.dLastUpdated = DateTime.Now;

                                db.TrPoints.AddObject(trPoint);
                                db.SaveChanges();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        result.status      = false;
                        result.message     = e.Message;
                        result.messageCode = "Error in saving article";
                        return(result);
                    }
                }
            }
            catch (Exception e)
            {
                result.status      = false;
                result.message     = e.Message;
                result.messageCode = "Error in saving Article";
            }

            return(result);
        }