Beispiel #1
0
        public async Task<IHttpActionResult> Register3()
        //public async Task<HttpResponseMessage>  Register2()
        {

            var contentType = Request.Content.Headers.ContentType.MediaType;
            var pp = System.Web.HttpContext.Current.Request["RegisterBindingModel"];

            RegisterBindingModel foo = Newtonsoft.Json.JsonConvert.DeserializeObject<RegisterBindingModel>(pp) as RegisterBindingModel;

            //  JsonSerializer serializer = JsonSerializer.Create(Configuration.Formatters.JsonFormatter.SerializerSettings);

            //  var requestParams = Request.Content.ReadAsStringAsync().Result;


            var httpRequest = HttpContext.Current.Request;



            if (httpRequest.Files.Count > 0)
            {
                foreach (string file in httpRequest.Files)
                {
                    var files = new List<string>();
                    if (file == "FileUpload")
                    {

                        var postedFile = httpRequest.Files[file];
                        var vfile = postedFile.FileName.Replace("\"", string.Empty).Replace("'", string.Empty);

                        vfile = Stp(vfile);
                        string FileName = HttpContext.Current.Server.MapPath("~/Img/" + vfile);
                        //   dd.cac_file = "/images/" + vfile;

                        foo.LogoPath = "Img/" + vfile;

                        postedFile.SaveAs(FileName);



                    }
                }

            }



            var user = new ApplicationUser() { UserName = foo.Email, Email = foo.Email, LogoPath = foo.LogoPath, Security_Question = foo.Security_Question, First_Name = foo.First_Name, Surname_Name = foo.Surname_Name, PhoneNumber = foo.PhoneNumber, Security_Answer = foo.Security_Answer, Subscription_Type = foo.Subscription_Type };
            foo.Password = CreatePassword(8);

            IdentityResult result = await UserManager.CreateAsync(user, foo.Password);

          //  ApplicationUser vv = UserManager.FindByEmail(foo.Email);
            ApplicationUser vv = UserManager.FindByEmail(foo.Email);




            IdentityResult result2 = await UserManager.AddToRoleAsync(vv.Id, "CORPORATE");
            var _db = new ApplicationDbContext();
            foreach (String ssd in foo.Services)
            {
                User_Detail gs = new User_Detail();
                gs.Fee_amount = foo.Fee_amount;
                gs.Services = ssd;
                
                gs.User_Id = foo.Email;
                gs.Fee = foo.Fee;

                _db.User_Detail.Add(gs);
                _db.SaveChanges();


            }
            foreach (String ssd in foo.Services)
            {
                Subscription_Detail2 hh = new Subscription_Detail2();
                hh.Payment_Date = DateTime.Now;
                hh.Subscription_Code = foo.Subscription_Type;
                hh.user_id = foo.Email;
                hh.Transaction_Code = "";
                hh.Service = ssd;
                if (foo.Fee)
                {

                    AddSubscription_Detail3(hh);

                }

            }
            // result = await UserManager.AddToRoleAsync(vv.Id, "INSTITUTION");

            //if (!result.Succeeded)
            //{

            //    return GetErrorResult(result);
            //}
            //  return   Request.CreateErrorResponse(HttpStatusCode.Created,
            //  "Record Successfully Created");

            sendemail2(foo.Email, foo.Email, foo.Password);   
            return Ok();
        }
Beispiel #2
0
        public async Task<String> AddTransaction3(Transaction foo)
        {



            var httpRequest = HttpContext.Current.Request;





            try
            {
                var _db = new ApplicationDbContext();
                //  string currentUserId = User.Identity.GetUserId();
                Transaction aaa = new Transaction();
                aaa.amount = foo.amount;
                aaa.Bank_Code = foo.Bank_Code;
                aaa.Institution_Code = foo.Institution_Code;
                aaa.Payment_Status = "Pending";
                //if (foo.Transaction_Status == "Approved")
                //{
                //    aaa.Payment_Status = "Paid";
                //}

                //else
                //{

                //    aaa.Payment_Status = "error";
                //}
                aaa.Subscription_Code = foo.Subscription_Code;
                //  aaa.Transaction_Code = Generate15UniqueDigits();

                aaa.Transaction_Code = foo.Transaction_Code;
                aaa.payment_type = foo.payment_type;
                aaa.Account_Number = foo.Account_Number;
                aaa.user_id = foo.user_id;
                aaa.Status = "Unused";
                aaa.Order_Id = foo.Order_Id;
                aaa.Transaction_Date = DateTime.Now;
                aaa.Transaction_Status = foo.Transaction_Status;
                aaa.Service = foo.Service;
                _db.Transaction.Add(aaa);

                var kk = _db.SaveChanges();

                //Subscription_Detail2 hh = new Subscription_Detail2();
                //hh.Payment_Date = DateTime.Now;
                //hh.Subscription_Code = foo.Subscription_Code;
                //hh.user_id = foo.user_id;
                //hh.Transaction_Code = foo.Transaction_Code;
                //if (foo.Transaction_Status == "Approved")
                //{

                //    AddSubscription_Detail3(hh);

                //}
                //   _db.SaveChanges();

                var xk = (from c in _db.User_Detail where c.User_Id == foo.user_id && c.Services == foo.Subscription_Code select c).Count();
                if (xk > 0)
                {


                }
                else
                {

                    User_Detail gs = new User_Detail();
                    gs.Fee_amount = 0.0;
                    gs.Services = foo.Service;

                    gs.User_Id = foo.user_id;
                    gs.Fee = false;

                    _db.User_Detail.Add(gs);
                    _db.SaveChanges();
                }
                return aaa.Transaction_Code;

            }
            catch (Exception ee)
            {
                return ee.Message; ;
            }




        }