コード例 #1
0
        public async Task <ActionResult <SpecialOfferUsers> > PostSpecialOfferUsers(SpecialOfferUsers specialOfferUsers)
        {
            var claimsIdentity = this.User.Identity as ClaimsIdentity;
            var Myusername     = claimsIdentity.FindFirst(ClaimTypes.Surname)?.Value;



            specialOfferUsers.UserId               = int.Parse(User.Identity.Name);
            specialOfferUsers.CreatedBy            = Myusername;
            specialOfferUsers.SpecialOfferUserName = Myusername;
            specialOfferUsers.CreatedDate          = DateTime.Now;

            Guid   g          = Guid.NewGuid();
            string GuidString = Convert.ToBase64String(g.ToByteArray());

            GuidString = GuidString.Replace("=", "");
            GuidString = GuidString.Replace("+", "");
            specialOfferUsers.OfferVoutureCode = GuidString;

            var MaximumSubscribedUsers = _context.SpecialOfferUserss.Count(i => i.UserId > 0);

            if (MaximumSubscribedUsers >= 3)
            {
                return(BadRequest(new { message = "Only 2 Subscriptions Are Allowed.You Need to Unsubscribed Earler Subscriptions" }));
            }
            else
            {
                _context.SpecialOfferUserss.Add(specialOfferUsers);
                await _context.SaveChangesAsync();
            }

            //   return CreatedAtAction("GetSpecialOfferUsers", new { id = specialOfferUsers.SpecialOfferUserId }, specialOfferUsers);
            return(Ok(new
            {
                Message = "COngrats" + Myusername + "You have Subscribed" + specialOfferUsers + "Your VoutureCode Is" + specialOfferUsers.OfferVoutureCode + "You Got Descount Regarding To your VoutureCode",
                Id = specialOfferUsers.SpecialOfferUserId,
                OfferVoutureCode = specialOfferUsers.OfferVoutureCode,
                specialOfferUsers
            }));
        }
コード例 #2
0
        public async Task <IActionResult> PutSpecialOfferUsers(int id, string VoutureCode, SpecialOfferUsers specialOfferUsers)
        {
            var claimsIdentity = this.User.Identity as ClaimsIdentity;                // Calling User Data From Users Controller
            var Myusername     = claimsIdentity.FindFirst(ClaimTypes.Surname)?.Value; // Finding Current User

            if (id != specialOfferUsers.SpecialOfferUserId)
            {
                return(BadRequest());
            }
            specialOfferUsers.SpecialOfferUserId   = id;
            specialOfferUsers.ModifiedUserId       = int.Parse(User.Identity.Name); // Auto Update
            specialOfferUsers.ModifiedBy           = Myusername;                    // Auto Update
            specialOfferUsers.ModifiedDate         = DateTime.Now;                  // Auto Update
            specialOfferUsers.SpecialOfferUserName = Myusername;

            if (_context.SpecialOfferUserss.Any(V => V.OfferVoutureCode != VoutureCode))         // Getting Value From Database and Check IsEqual
            {
                return(BadRequest(new { message = "Your Vouture Code Is Invalid Please Enter Valid Vouture Code" }));
            }
            else
            {
                Guid   g          = Guid.NewGuid();
                string GuidString = Convert.ToBase64String(g.ToByteArray());
                GuidString = GuidString.Replace("=", "");
                GuidString = GuidString.Replace("+", "");
                specialOfferUsers.OfferVoutureCode = GuidString;

                _context.Entry(specialOfferUsers).State = EntityState.Modified;
            }
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpecialOfferUsersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }