Esempio n. 1
0
        public async Task <IHttpActionResult> setIsActiveToFalse(int activeProductID)
        {
            activeproductitem    toUpdate = (from c in db.activeproductitems where c.ActiveProductItems_ID == activeProductID select c).SingleOrDefault();
            DTOactiveproductitem dtoAct   = new DTOactiveproductitem(toUpdate);

            dtoAct.isActive          = false;
            toUpdate                 = EntityMapper.updateEntity(toUpdate, dtoAct);
            db.Entry(toUpdate).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public async Task <Boolean> CleanReselleDates()
        {
            Boolean toreturn = false;

            List <voucher> voucherlist = (from c in db.vouchers select c).ToList();

            foreach (voucher temp in voucherlist)
            {
                temp.voucherCreationDate = temp.voucherCreationDate.Value.AddMonths(-7);
                db.Entry(temp).State     = EntityState.Modified;
                await db.SaveChangesAsync();
            }

            return(toreturn);
        }
        public async Task <IHttpActionResult> Putinsuranceproduct(int InsuranceProduct_ID, DTOinsuranceproduct insuranceproduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (InsuranceProduct_ID != insuranceproduct.InsuranceProduct_ID)
            {
                return(BadRequest());
            }

            insuranceproduct toUpdate = db.insuranceproducts.Single(c => c.InsuranceProduct_ID == InsuranceProduct_ID);

            toUpdate = EntityMapper.updateEntity(toUpdate, insuranceproduct);
            db.Entry(toUpdate).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!insuranceproductExists(InsuranceProduct_ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 4
0
        public async Task <IHttpActionResult> Putproduct(int id, DTOproduct productDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productDTO.Product_ID)
            {
                return(BadRequest());
            }

            var putProd = db.products.Single(e => e.Product_ID == id);

            db.Entry(EntityMapper.updateEntity(putProd, productDTO)).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!productExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> putUser(int id, DTOusertype dtousertype)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dtousertype.UserType_ID)
            {
                return(BadRequest());
            }

            var putUsertype = db.usertypes.Single(e => e.UserType_ID == id);

            db.Entry(EntityMapper.updateEntity(putUsertype, dtousertype)).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!userExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 6
0
        //returns users associated address. if user has no address -> give user address -> return new address. permission params - assign permissions if new address is created.
        // public static async Task<string> getAddress(MultiChainClient client, int userID, params BlockchainPermissions[] paramPermissions)
        public static async Task <string> getAddress(MultiChainClient client, int userID)
        {
            user tmp = new user();

            tmp.User_ID = -1;
            tmp         = await db.users.SingleAsync(l => l.User_ID == userID);

            if (tmp.User_ID != -1)
            {
                if (tmp.blockchainAddress == null)
                {
                    //get new address, get user for which address does not exist, add address to user record.
                    var newAddress = await client.GetNewAddressAsync();

                    newAddress.AssertOk();
                    string newAddr = newAddress.Result;
                    //give permissions
                    // var grant1 = client.GrantAsync(new List<string>() { newAddr }, BlockchainPermissions.Send);
                    //var grant2 = client.GrantAsync(new List<string>() { newAddr }, BlockchainPermissions.Receive);

                    tmp.blockchainAddress = newAddress.Result;
                    db.Entry(tmp).State   = EntityState.Modified;
                    db.SaveChanges();

                    //if(paramPermissions.Length > 0)
                    //{
                    //    MUserController tmpUser = new MUserController(userID);
                    //    tmpUser = await tmpUser.init();
                    //    await tmpUser.grantPermissions(paramPermissions);
                    //}

                    return(newAddress.Result);
                }
                else
                {
                    return(tmp.blockchainAddress);
                }
            }
            else
            {
                throw new KeyNotFoundException();
            }
        }
        public async Task <IHttpActionResult> putAdditionalSignUpInfo(int userID, string consumerAddress, string homeOwnerType, Nullable <int> numDependants, string topProductsInterestedIn, Nullable <decimal> grossMonthly, Nullable <decimal> nettMonthly, Nullable <decimal> totalExpenses)
        {
            consumer    toUpdate    = (from c in db.consumers where c.User_ID == userID select c).SingleOrDefault();
            DTOconsumer dtoConsumer = new DTOconsumer(toUpdate);

            dtoConsumer.consumerAddress = consumerAddress;
            dtoConsumer.homeOwnerType   = homeOwnerType;
            dtoConsumer.numDependant    = numDependants;
            dtoConsumer.topProductCategoriesInterestedIn = topProductsInterestedIn;
            dtoConsumer.grossMonthlyIncome   = grossMonthly;
            dtoConsumer.nettMonthlyIncome    = nettMonthly;
            dtoConsumer.totalMonthlyExpenses = totalExpenses;
            toUpdate = EntityMapper.updateEntity(toUpdate, dtoConsumer);
            db.Entry(toUpdate).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.OK));
        }
Esempio n. 8
0
        public IHttpActionResult sendUserOTPAndSaveOTP(int UserID, bool isResend)
        {
            string userPhoneNum    = getPhoneNumFromUserID(UserID);
            string correctPhoneNum = getCorrectPhoneNumFormat(userPhoneNum);
            string newOTP          = generateOTP();

            otpview    toUpdate   = (from c in db.otpviews where c.User_ID == UserID select c).SingleOrDefault();
            DTOotpview dtoOtpView = new DTOotpview(toUpdate);



            if (isResend)
            {
                dtoOtpView.otpRetryCount += 1;    //increment the retrycount
                if (dtoOtpView.otpRetryCount < 3) //still a valid attempt
                {
                    sendEmailViaWebApi(correctPhoneNum, "Hello from Nanofin! Your OTP for your transaction is: " + newOTP);
                    dtoOtpView.otpCode = newOTP;
                    //dtoOtpView.otpRetryCount has been set above
                    dtoOtpView.otpExpirationTime  = DateTime.Now.AddMinutes(3);
                    dtoOtpView.otpNextAllowedTime = null; //remains null as long as the user isn't blocked
                    dtoOtpView.otpRecordCreated   = DateTime.Now;

                    toUpdate = EntityMapper.updateEntity(toUpdate, dtoOtpView);
                    db.Entry(toUpdate).State = EntityState.Modified;
                    db.SaveChanges();
                    return(Content(HttpStatusCode.OK, "OTP Resent Successfully"));
                }
                if (dtoOtpView.otpRetryCount == 3)//too many attempts: user can request new OTP after a defined time=>blocked
                {
                    dtoOtpView.otpCode            = null;
                    dtoOtpView.otpRetryCount      = 3;
                    dtoOtpView.otpExpirationTime  = null;
                    dtoOtpView.otpNextAllowedTime = DateTime.Now.AddMinutes(2);//block time
                    dtoOtpView.otpRecordCreated   = DateTime.Now;

                    toUpdate = EntityMapper.updateEntity(toUpdate, dtoOtpView);
                    db.Entry(toUpdate).State = EntityState.Modified;
                    db.SaveChanges();
                    return(Content(HttpStatusCode.OK, "User blocked, OTP not Resent"));
                }
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else //not a resend: first time being sent
            {
                Nullable <DateTime> nowTime = DateTime.Now;
                //check if user is blocked: User is not blocked timeNow>next allowed time
                if (dtoOtpView.otpNextAllowedTime == null || (Nullable.Compare(nowTime, dtoOtpView.otpNextAllowedTime) > 0))
                {
                    sendEmailViaWebApi(correctPhoneNum, "Hello from Nanofin! Your OTP for your transaction is: " + newOTP);
                    dtoOtpView.otpCode            = newOTP;
                    dtoOtpView.otpRetryCount      = 0;
                    dtoOtpView.otpExpirationTime  = DateTime.Now.AddMinutes(1); //expiry time
                    dtoOtpView.otpNextAllowedTime = null;                       //remains null as long as the user isn't blocked
                    dtoOtpView.otpRecordCreated   = DateTime.Now;

                    toUpdate = EntityMapper.updateEntity(toUpdate, dtoOtpView);
                    db.Entry(toUpdate).State = EntityState.Modified;
                    db.SaveChanges();
                    return(Content(HttpStatusCode.OK, "OTP Sent sucessfully first time"));
                }
                else //user is still blocked
                {
                    return(Content(HttpStatusCode.OK, "User is still blocked"));
                }
            }
        }
        public async Task <IHttpActionResult> Putactiveproductitem(int ID, DTOactiveproductitem editedDTO)
        {
            //
            activeproductitem toUpdate = db.activeproductitems.Find(ID);

            toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO);
            db.Entry(toUpdate).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }