public async Task <IActionResult> Create([Bind("Itemid,Itemname,Itemcategory,Itemdescription,Purchaseprice,Purchasedate,Itemimage,Receiptimage,Upc,Userid,Policyid")] PolicyItems policyItems)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var currentEmail = user.Email;
            var newUserId    = await _context.PolicyHolder.FirstOrDefaultAsync(p => p.Email == currentEmail);

            if (ModelState.IsValid)
            {
                policyItems.Userid = newUserId.Userid;
                _context.Add(policyItems);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Policyid"] = new SelectList(_context.PolicyDetails.Where(p => p.User.Userid == newUserId.Userid), "Policyid", "Policynickname", policyItems.Policyid);
            //ViewData["Userid"] = new SelectList(_context.PolicyHolder, "Userid", "Email", policyItems.Userid);
            return(View(policyItems));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Itemid,Itemname,Itemcategory,Itemdescription,Purchaseprice,Purchasedate,Itemimage,Receiptimage,Upc,Userid,Policyid")] PolicyItems policyItems)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var currentEmail = user.Email;
            var newUserId    = await _context.PolicyHolder.FirstOrDefaultAsync(p => p.Email == currentEmail);

            if (id != policyItems.Itemid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(policyItems);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PolicyItemsExists(policyItems.Itemid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Policyid"] = new SelectList(_context.PolicyDetails.Where(p => p.User.Userid == newUserId.Userid), "Policyid", "Policynickname", policyItems.Policyid);
            //ViewData["Userid"] = new SelectList(_context.PolicyHolder, "Userid", "Email", policyItems.Userid);
            return(View(policyItems));
        }
Beispiel #3
0
        public void AddPolicy(string FileName)
        {
            BinaryReader binaryStream = new BinaryReader(File.OpenRead(FileName), Encoding.Unicode);

            PolicyItem PolItem = new PolicyItem();

            int length     = (int)binaryStream.BaseStream.Length;
            int pos        = 0;
            int CurrentPos = POSITION_REG_END;

            if (length >= sizeof(int) * 2)
            {
                Signature   = binaryStream.ReadInt32();
                FileVersion = binaryStream.ReadInt32();
                pos        += sizeof(int) * 2;
            }

            while (pos < length)
            {
                if (CurrentPos == POSITION_REG_END || CurrentPos == POSITION_REG_KEY ||
                    CurrentPos == POSITION_REG_VALUE)
                {
                    char NextChar = binaryStream.ReadChar();
                    pos += sizeof(char);

                    if (NextChar == '[' && CurrentPos == POSITION_REG_END)
                    {
                        PolItem    = new PolicyItem();
                        CurrentPos = POSITION_REG_KEY;
                    }
                    else if (NextChar == ']' && CurrentPos == POSITION_REG_END)
                    {
                        PolicyItems.Add(PolItem);
                    }
                    else if (NextChar != ';' && CurrentPos == POSITION_REG_KEY)
                    {
                        if (NextChar != '\0')
                        {
                            PolItem.Key += NextChar;
                        }
                    }
                    else if (NextChar == ';' && CurrentPos == POSITION_REG_KEY)
                    {
                        CurrentPos = POSITION_REG_VALUE;
                    }
                    else if (NextChar != ';' && CurrentPos == POSITION_REG_VALUE)
                    {
                        if (NextChar != '\0')
                        {
                            PolItem.Value += NextChar;
                        }
                    }
                    else if (NextChar == ';' && CurrentPos == POSITION_REG_VALUE)
                    {
                        CurrentPos = POSITION_REG_TYPE;
                    }
                }
                else if (CurrentPos == POSITION_REG_TYPE)
                {
                    PolItem.Type = binaryStream.ReadInt32();
                    pos         += sizeof(int);
                    CurrentPos   = POSITION_REG_SIZE;

                    if (pos < length)
                    {
                        binaryStream.ReadChar();
                        pos += sizeof(char);
                    }
                }
                else if (CurrentPos == POSITION_REG_SIZE)
                {
                    PolItem.Size = binaryStream.ReadInt32();
                    pos         += sizeof(int);
                    CurrentPos   = POSITION_REG_DATA;

                    if (pos < length)
                    {
                        binaryStream.ReadChar();
                        pos += sizeof(char);
                    }

                    if ((pos + PolItem.Size) < length)
                    {
                        PolItem.SetData(binaryStream.ReadBytes(PolItem.Size), PolItem.Size);
                        CurrentPos = POSITION_REG_END;
                        pos       += PolItem.Size;
                    }
                }
            }


            binaryStream.Close();
        }