Esempio n. 1
0
        protected void GenerateSpriteCache()
        {
            foreach (SelectionItem item in traitItems.Values)
            {
                float     aspect = 0;
                Texture2D tex    = GetTexture(item.GetKey(), out aspect);
                if (tex == null)
                {
                    continue;
                }

                ItemDraw spriteData = new ItemDraw();
                spriteData.color  = item.GetColor();
                spriteData.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 1, 0, SpriteMeshType.FullRect);

                spriteData.height = 3.95f;
                spriteData.width  = spriteData.height * tex.width / tex.height;
                if (aspect != 0)
                {
                    spriteData.width = spriteData.height * aspect;
                }
                if (spriteData.width > 20)
                {
                    spriteData.width  = 20;
                    spriteData.height = spriteData.width * tex.height / tex.width;
                }
                spriteCache.Add(item.GetKey(), spriteData);
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> CreateItemDraw([FromBody] ItemDraw itemdraw)
        {
            //get headers
            //string headervalue1 = "";
            //string headervalue2 = "";
            //Helper helper = new Helper();
            //if (helper.IsTransactionAutheticated(headervalue1, headervalue2))
            //{


            List <int> itemids   = new List <int>();
            int        newitemid = 1;
            //if (!(items.Ticketamount.ToString().Contains("."))) {
            decimal amount = Math.Round(Convert.ToDecimal(itemdraw.amount), 2);

            DateTime curdate = DateTime.Parse(DateTime.UtcNow.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss"));
            //normalize drawdate to 7.30PM - next four lines
            string stringeddatetime = itemdraw.drawdate.ToString();

            string[] splitdate         = stringeddatetime.Split("T");
            string   completeddatetime = splitdate[0] + "T18:30:00.000Z";
            DateTime drawdatetime      = DateTime.Parse(completeddatetime);
            string   newitemname;
            var      draww     = new Draws();
            Items    itemm     = new Items();
            var      itemcheck = await _context.Items.Where(x => x.Itemname.Contains(itemdraw.itemname)).FirstOrDefaultAsync();

            if (itemcheck == null)
            {
                //create new item in the format "iphone11-1(for item name)"
                newitemname           = itemdraw.itemname.ToLower() + "-" + newitemid.ToString();
                itemm.Categoryid      = itemdraw.catid;
                itemm.Itemdescription = itemdraw.itemdescription;
                itemm.Itemname        = newitemname;
                itemm.Ticketamount    = amount;
                itemm.Datecreated     = curdate;
                itemm.Datemodified    = curdate;
            }

            else
            {
                // retrieve record that has the highest number attached to it.
                var itemcheck2 = await _context.Items.Where(x => x.Itemname.Contains(itemdraw.itemname)).ToListAsync();

                foreach (var i in itemcheck2)
                {
                    string[] splititems = i.Itemname.Split('-');
                    itemids.Add(Convert.ToInt32(splititems[1]));
                }

                newitemid             = itemids.Max() + 1;
                newitemname           = itemdraw.itemname.ToLower() + "-" + newitemid.ToString();
                itemm.Categoryid      = itemdraw.catid;
                itemm.Itemdescription = itemdraw.itemdescription;
                itemm.Itemname        = newitemname;
                itemm.Ticketamount    = amount;
                itemm.Datecreated     = curdate;
                itemm.Datemodified    = curdate;
            }


            _context.Items.Add(itemm);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException ex)
            {
                if (ItemsExists(itemm.Id))
                {
                    var data = new
                    {
                        status    = "fail",
                        message   = "An item already exists with the same ID",
                        exception = ex.Message
                    };
                    _logger.LogError(ex, data.message);
                    return(new JsonResult(data));
                }
                else
                {
                    var data = new
                    {
                        status    = "fail",
                        message   = "An error occured while attempting to save new item",
                        exception = ex.Message
                    };
                    _logger.LogError(ex, data.message);
                    return(new JsonResult(data));
                    //throw;
                }
            }
            //if get here, then new item create successfully
            _logger.LogInformation("New item with item name" + itemm.Itemname + " created successfully");

            //get newly created item
            var createditem = await _context.Items.Where(x => x.Itemname == itemm.Itemname).FirstOrDefaultAsync();

            //save draw
            draww.DrawType = itemdraw.drawtype;
            //draww.Drawdate = DateTime.Parse(itemdraw.drawdate);
            draww.Drawdate     = drawdatetime.AddHours(1);
            draww.Drawstatus   = DrawStatus.Live;
            draww.drawwinners  = itemdraw.qty;
            draww.Itemid       = createditem.Id;
            draww.Datemodified = curdate;
            draww.Datecreated  = curdate;

            //add draw
            _context.Draws.Add(draww);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException ex)
            {
                if (ItemsExists(draww.Id))
                {
                    var data = new
                    {
                        status    = "fail",
                        message   = "A draw already exists with the same ID",
                        exception = ex.Message
                    };
                    _logger.LogError(ex, data.message, ex.Message);
                    return(new JsonResult(data));
                }
                else
                {
                    var data = new
                    {
                        status    = "fail",
                        message   = "An error occured while attempting to save new item",
                        exception = ex.Message
                    };
                    _logger.LogError(ex, data.message, ex.Message);
                    return(new JsonResult(data));
                }
            }
            _logger.LogInformation("Draw with draw ID" + draww.Id + "created successfully");
            var data2 = new
            {
                status     = "Saved! Copy the name shown below into the next field, then click 'Create Giveaway' ",
                message    = "Item Created Successfully",
                dbitemname = newitemname
            };

            return(new JsonResult(data2));
            //}


            //else
            //{
            //    var data3 = new
            //    {
            //        status = "fail",
            //        message = "Client Authentication failure",
            //    };
            //    return new JsonResult(data3);
            //}
        }