public async Task <IActionResult> AddAndEditColor(ColorCustom data)
        {
            #region Authorization code
            var    identity = HttpContext.User.Identity as ClaimsIdentity;
            string id       = "";
            string role     = "";
            if (identity != null)
            {
                IEnumerable <Claim> claims = identity.Claims;
                // or
                id   = identity.Claims.Where(m => m.Type == ClaimTypes.Sid).Select(m => m.Value).FirstOrDefault();
                role = identity.Claims.Where(m => m.Type == ClaimTypes.Role).Select(m => m.Value).FirstOrDefault();
            }
            long userId = Convert.ToInt32(id);
            #endregion
            //calling ColorDAL busines layer
            CommonResponse response = new CommonResponse();
            response = colorMaster.AddAndEditColor(data, userId);

            return(Ok(response));
        }
Ejemplo n.º 2
0
        public static Bitmap ConvertToBitmap(DisjointSet segmentedSet, int height, int width, out int segmentsCount)
        {
            double[,,] im = new double[3, height, width];

            Dictionary <int, ColorCustom> colors = new Dictionary <int, ColorCustom>();
            int totalSize = 0;

            for (int h = 0; h < height; h++)
            {
                for (int w = 0; w < width; w++)
                {
                    ColorCustom ccc;

                    int comp = segmentedSet.Find(h * width + w);

                    if (colors.TryGetValue(comp, out ccc) == false)
                    {
                        ccc = ColorCustom.GetRandomColor();
                        colors.Add(comp, ccc);

                        int compSize = segmentedSet.Size(comp);
                        totalSize += compSize;
                        System.Diagnostics.Debug.WriteLine("Component: " + comp + " | size: " + compSize);
                    }


                    im[0, h, w] = BitmapConverter.Limit(ccc.r);
                    im[1, h, w] = BitmapConverter.Limit(ccc.g);
                    im[2, h, w] = BitmapConverter.Limit(ccc.b);
                }
            }

            System.Diagnostics.Debug.WriteLine("Total Size: " + totalSize);
            System.Diagnostics.Debug.WriteLine("Height*Width: " + height * width);

            segmentsCount = colors.Count;
            return(BitmapConverter.DoubleRgbToBitmap(im));
        }
Ejemplo n.º 3
0
        public static Bitmap RealCoordsSegmentResultToBitmap(RealCoordsSegmentResult r)
        {
            double[,,] im = new double[3, r.imageheight, r.imageWidth];

            var segments = r.realCoordsSegments;

            for (int s = 0; s < segments.Length; s++)
            {
                ColorCustom ccc    = ColorCustom.GetRandomColor();
                Point[]     points = segments[s].coords;

                for (int i = 0; i < points.Length; i++)
                {
                    int y = points[i].Y;
                    int x = points[i].X;

                    im[0, y, x] = ccc.r;
                    im[1, y, x] = ccc.g;
                    im[2, y, x] = ccc.b;
                }
            }

            return(BitmapConverter.DoubleRgbToBitmap(im));
        }
        /// <summary>
        /// Add and Edit Document
        /// </summary>
        /// <param name="data"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public CommonResponse AddAndEditColor(ColorCustom data, long userId = 0)
        {
            CommonResponse obj = new CommonResponse();

            try
            {
                var res = db.ColorMaster.Where(m => m.ColorId == data.colorId).FirstOrDefault();
                if (res == null)
                {
                    try
                    {
                        ColorMaster item = new ColorMaster();
                        item.ColorName        = data.colorName;
                        item.ColorCode        = data.colorCode;
                        item.ColorDescription = data.colorDescription;
                        item.IsActive         = true;
                        item.IsDeleted        = false;
                        item.CreatedBy        = userId;
                        item.CreatedOn        = DateTime.Now;
                        db.ColorMaster.Add(item);
                        db.SaveChanges();
                        obj.response = ResourceResponse.AddedSucessfully;
                        obj.isStatus = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
                else
                {
                    try
                    {
                        res.ColorName        = data.colorName;
                        res.ColorCode        = data.colorCode;
                        res.ColorDescription = data.colorDescription;
                        res.ModifiedBy       = userId;
                        res.ModifiedOn       = DateTime.Now;
                        db.SaveChanges();
                        obj.response = ResourceResponse.UpdatedSucessfully;
                        obj.isStatus = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex); if (ex.InnerException != null)
                {
                    log.Error(ex.InnerException.ToString());
                }
                obj.response = ResourceResponse.ExceptionMessage;
                obj.isStatus = false;
            }
            return(obj);
        }