public async Task <IActionResult> Create([Bind("ProductId,Name,Price,Description,Active,Slug,CategoryId")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);

                var imgFile = Request.Form.Files["image"];

                if (imgFile != null || imgFile.Length > 0)
                {
                    Image img = new Image();
                    img.Path = imgFile.FileName;

                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "img", imgFile.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await imgFile.CopyToAsync(stream);
                    }


                    img.Product = product;
                    _context.Images.Add(img);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", product.CategoryId);
            return(View(product));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create([Bind(Include = "id,cus_type_code,bran_code,rel_off_code,title,firstname,lastname,middlename,dob,age_cat_type_code,gender,occupation_code,img_url,sign_img_url,marital_status,child_num,home_type_code,cus_since,cus_other_code,kin_details_code,contact_code,cus_doc_code,credit_limit,created_by,modified_by,deleted_by,created_date,modified_date,deleted_date")] app_cus_main app_cus_main)
        {
            var results = CheckCustomer(app_cus_main.gender, app_cus_main.firstname, app_cus_main.lastname, app_cus_main.middlename, app_cus_main.dob, app_cus_main.app_cus_other_info.verification_id, app_cus_main.app_cus_contact.tele_number);

            if (results)
            {
                ModelState.AddModelError(string.Empty, "Customer Already Exist");
            }

            if (ModelState.IsValid)
            {
                db.app_cus_main.Add(app_cus_main);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.age_cat_type_code = new SelectList(db.app_age_cate, "id", "age_code", app_cus_main.age_cat_type_code);
            ViewBag.bran_code         = new SelectList(db.app_branch, "id", "branch_name", app_cus_main.bran_code);
            ViewBag.contact_code      = new SelectList(db.app_cus_contact, "id", "tele_number", app_cus_main.contact_code);
            ViewBag.cus_doc_code      = new SelectList(db.app_cus_doc, "id", "cus_doc_name", app_cus_main.cus_doc_code);
            ViewBag.cus_other_code    = new SelectList(db.app_cus_other_info, "id", "cus_other_code", app_cus_main.cus_other_code);
            ViewBag.cus_type_code     = new SelectList(db.app_cus_type, "id", "cus_type_code", app_cus_main.cus_type_code);
            ViewBag.kin_details_code  = new SelectList(db.app_kin_details, "id", "kin_details_code", app_cus_main.kin_details_code);
            ViewBag.occupation_code   = new SelectList(db.app_occupation, "id", "occ_code", app_cus_main.occupation_code);
            ViewBag.rel_off_code      = new SelectList(db.app_rel_office, "id", "rel_code", app_cus_main.rel_off_code);
            return(View(app_cus_main));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "id,bran_code,branch_name,bran_type_code,address1,address2,state,zip,assets")] app_branch app_branch)

        {
            ViewBag.alert = "";

            //var ck = _repository.CheckCustomer(app_cus_main.gender, app_cus_main.firstname, app_cus_main.lastname, app_cus_main.middlename, app_cus_main.dob, app_cus_other_info.verification_id, app_cus_contact.tele_number);


            //if (ck)
            //{
            //    ModelState.AddModelError("", "Branch Already exist");
            //}



            if (ModelState.IsValid)
            {
                db.app_branch.Add(app_branch);
                await db.SaveChangesAsync();

                ViewBag.alert = "saved";
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.alert = "error";
            }

            var errors = ModelState.Values.SelectMany(v => v.Errors);

            ViewBag.bran_type_code = new SelectList(db.app_bran_type, "id", "name", app_branch.bran_type_code);
            return(View(app_branch));
        }
Exemplo n.º 4
0
        public async Task <StudentDetails> CreateAsync(StudentDetails entity)
        {
            var res = await ctx.StudentDetails.AddAsync(entity);

            await ctx.SaveChangesAsync();

            return(res.Entity);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("CategoryId,Name,Slug")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("PaymentMethodId,Name")] PaymentMethod paymentMethod)
        {
            if (ModelState.IsValid)
            {
                _context.Add(paymentMethod);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(paymentMethod));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("OrderId,Time,CustomerName,Note,ShipAdress,ContactNumber,PaymentId")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PaymentId"] = new SelectList(_context.Payments, "PaymentId", "PaymentId", order.PaymentId);
            return(View(order));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("ImageId,Path,ProductId")] Image image)
        {
            if (ModelState.IsValid)
            {
                _context.Add(image);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductId", image.ProductId);
            return(View(image));
        }
        public async Task <ActionResult> Create([Bind(Include = "ID,DatePosted,RecNo,US_Dollars,BritishPounds,Yen,CFA,Euro,CanDollar,Rate,TotalAmount,UserPosted,UserModified")] tb_sales_transactions tb_sales_transactions)
        {
            if (ModelState.IsValid)
            {
                db.tb_sales_transactions.Add(tb_sales_transactions);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(tb_sales_transactions));
        }
        public async Task <ActionResult> Create([Bind(Include = "id,contact_code,tele_number,fax,email,address1,address2,city,state,zip,brief_location,gps_cordinates")] app_cus_contact app_cus_contact)
        {
            if (ModelState.IsValid)
            {
                db.app_cus_contact.Add(app_cus_contact);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(app_cus_contact));
        }
Exemplo n.º 11
0
        public async Task <UserPreferences> Update(int id, string preference)
        {
            try
            {
                var res = await ctx.UserPreferences.FindAsync(id);

                res.PreferanceValue = preference;
                await ctx.SaveChangesAsync();

                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 12
0
        public async Task <ActionResult> CreateCustomer([Bind(Include = "id,citizenship,home_type_code,age_cat_type_code,cus_type_code,title,firstname,lastname,middlename,dob,gender,security_code,occupation_code,img_url,sign_img_url,marital_status,child_num,cus_since,cus_doc_code,credit_limit,kin_type_code,created_by,modified_by,deleted_by,created_date,modified_date,deleted_date,rel_off_code,bran_code")]
                                                        app_cus_main app_cus_main
                                                        , app_cus_other_info app_cus_other_info
                                                        , app_cus_contact app_cus_contact
                                                        , app_gender app_gender
                                                        , app_kin_details app_kin_details

                                                        )
        {
            ViewBag.alert = "";

            var ck = _repository.CheckCustomer(app_cus_main.gender, app_cus_main.firstname, app_cus_main.lastname, app_cus_main.middlename, app_cus_main.dob, app_cus_other_info.verification_id, app_cus_contact.tele_number);


            if (ck)
            {
                ModelState.AddModelError("", "Customer Already exist");
            }



            if (ModelState.IsValid)
            {
                app_cus_main.created_by         = _repository.GetLoginUser();
                app_cus_main.created_date       = _repository.GetCurrentDateTime();
                app_cus_main.cus_since          = _repository.GetCurrentDateTime();
                app_cus_main.img_url            = "/image/photo";
                app_cus_main.status             = "ini";
                app_cus_main.sign_img_url       = "/image/signature";
                app_cus_main.app_cus_contact    = app_cus_contact;
                app_cus_main.app_kin_details    = app_kin_details;
                app_cus_main.app_cus_other_info = app_cus_other_info;

                app_cus_main.cus_code = _repository.GetCustomerCode(app_cus_main.id);
                db.app_cus_main.Add(app_cus_main);
                await db.SaveChangesAsync();

                ViewBag.alert = "saved";
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.alert = "error";
            }

            var errors = ModelState.Values.SelectMany(v => v.Errors);

            ViewBag.citizenship       = new SelectList(db.app_countries, "id", "name");
            ViewBag.home_type_code    = new SelectList(db.app_home_type, "id", "type_name", app_cus_main.home_type_code);
            ViewBag.gender            = new SelectList(db.app_gender, "id", "sex", app_cus_main.gender);
            ViewBag.age_cat_type_code = new SelectList(db.app_age_cate, "id", "name_of_cat", app_cus_main.age_cat_type_code);
            ViewBag.bran_code         = new SelectList(db.app_branch, "id", "branch_name", app_cus_main.bran_code);
            ViewBag.contact_code      = new SelectList(db.app_cus_contact, "id", "tele_number", app_cus_main.contact_code);
            ViewBag.cus_doc_code      = new SelectList(db.app_cus_doc, "id", "cus_doc_name", app_cus_main.cus_doc_code);
            ViewBag.cus_other_code    = new SelectList(db.app_cus_other_info, "id", "cus_other_code", app_cus_main.cus_other_code);
            ViewBag.cus_type_code     = new SelectList(db.app_cus_type, "id", "type_name", app_cus_main.cus_type_code);
            ViewBag.kin_details_code  = new SelectList(db.app_kin_details, "id", "kin_details_code", app_cus_main.kin_details_code);
            ViewBag.occupation_code   = new SelectList(db.app_occupation, "id", "name", app_cus_main.occupation_code);
            ViewBag.rel_off_code      = new SelectList(db.app_rel_office, "id", "full_name", app_cus_main.rel_off_code);
            ViewBag.home_type_code    = new SelectList(db.app_home_type, "id", "type_name");

            return(View(app_cus_main));
        }
Exemplo n.º 13
0
        public async Task <ActionResult> CreateImport(app_file model)
        {
            //Chcking if modelState is valid or not.
            if (ModelState.IsValid)
            {
                ViewBag.alert = "";
                //Create an object of Service class.
                //---   UploadService service = new UploadService();
                //Saved the uploaded file details to database.
                //---   string fileGuid = service.SaveFileDetails(model);
                //The file is then saved to physical folder.
                string savedFileName = "~/Doc/" + "_" + "000_imp" + model.File.FileName;
                model.File.SaveAs(Server.MapPath(savedFileName));

                //The below code reads the excel file.
                var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0;", Server.MapPath(savedFileName));
                var adapter          = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
                var ds = new DataSet();
                adapter.Fill(ds, "results");
                DataTable data = ds.Tables["results"];

                //The excel file is validated for data entered in excel file.
                // bool isValid = _repository.ValidateExcelFileData(data);
                // if (isValid)
                // {
                //If the excel file uploaded validates to true then the data mentioned is saved to database.
                foreach (DataRow row in data.Rows)
                {
                    app_cus_main       app_cus     = new app_cus_main();
                    app_cus_contact    app_contact = new app_cus_contact();
                    app_cus_other_info app_info    = new app_cus_other_info();
                    app_cus_type       app_type    = new app_cus_type();
                    app_occupation     app_occ     = new app_occupation();
                    app_rel_office     app_rel     = new app_rel_office();
                    app_branch         app_bra     = new app_branch();
                    app_gender         app_gen     = new app_gender();


                    app_cus.cus_code   = row["CUST_ID"].ToString();
                    app_cus.title      = row["TITLE"].ToString();
                    app_cus.firstname  = row["FIRST_NAME"].ToString();
                    app_cus.middlename = row["OTHER_NAME"].ToString();
                    app_cus.lastname   = row["LAST_NAME"].ToString();

                    //CUSTOMER TYPE
                    //FK app_cus.cus_type_code = Convert.ToInt32(row["CUSTOMER_TYPE"]);
                    app_type.type_name = row["CUSTOMER_TYPE"].ToString();

                    //GENDER
                    app_gen.sex = row["GENDER"].ToString();

                    app_cus.dob = Convert.ToDateTime(row["DATE_BIRTH"]);

                    //contact
                    app_contact.address2     = row["HOUSE_NUMBER"].ToString();
                    app_contact.tele_number  = row["TEL_1"].ToString();
                    app_contact.tele_number2 = row["TEL_2"].ToString();
                    app_contact.email        = row["EMAIL"].ToString();

                    app_contact.address1 = row["ADDRESS"].ToString();

                    //OTHER INFO
                    app_info.verification_id = row["VERI_ID"].ToString();
                    app_info.security_group  = row["SECURITY_GROUP"].ToString();

                    if (row["SECURITY_GROUP"].ToString() == null || row["SECURITY_GROUP"].ToString() == string.Empty)
                    {
                        app_info.security_group = "Public";
                    }


                    //OCCUPATION
                    //FK app_cus.occupation_code = Convert.ToInt32(row["OCCUPATION"]);


                    app_occ.name = row["OCCUPATION"].ToString();

                    app_cus.marital_status = row["MARITAL_STATUS"].ToString();


                    //relations office
                    // app_cus.rel_off_code = Convert.ToInt32(row["GENDER"]);
                    app_cus.rel_off_code = (int)row["REL_ID"];


                    //app_rel.firstname = row["RELATION_OFFICER_FIRSTNAME"].ToString();
                    //app_rel.lastname = row["RELATION_OFFICER_LASTNAME"].ToString();
                    //app_rel.middlename = row["RELATION_OFFICER_OTHERNAME"].ToString();

                    //BRANCH
                    //FK
                    // app_cus.bran_code =  Convert.ToInt32(row["BRANCH"]);

                    app_bra.branch_name = row["BRANCH"].ToString();


                    //save to db
                    app_cus.created_by   = _repository.GetLoginUser();
                    app_cus.created_date = _repository.GetCurrentDateTime();
                    app_cus.cus_since    = _repository.GetCurrentDateTime();
                    app_cus.img_url      = "/image/photo";
                    app_cus.status       = "ini";
                    app_cus.sign_img_url = "/image/signature";


                    app_cus.app_cus_contact    = app_contact;
                    app_cus.app_cus_other_info = app_info;
                    app_cus.app_cus_type       = app_type;
                    app_cus.app_occupation     = app_occ;
                    app_cus.app_rel_office     = app_rel;
                    app_cus.app_branch         = app_bra;
                    app_cus.app_gender         = app_gen;

                    if (TryValidateModel(app_cus))
                    {
                        var errors = ModelState.Values.SelectMany(v => v.Errors);

                        db.app_cus_main.Add(app_cus);
                        ViewBag.alert = "saved";
                        await db.SaveChangesAsync();
                    }
                    else
                    {
                        var errors = ModelState.Values.SelectMany(v => v.Errors);

                        ViewBag.alert = "error";
                        return(View(app_cus));
                    }

                    //   app_cus_main.cus_code = _repository.GetCustomerCode(app_cus_main.id);

                    //_repository.SaveUserDetails(firstname, lastname, age, email, password);
                }
                return(View("Index"));
                //  _repository.UpdateExcelStatus(Guid.Parse(fileGuid), true, string.Empty);
                // }
                // else
                //  {
                // _repository.UpdateExcelStatus(Guid.Parse(fileGuid), true, "Failure");
                //  }
            }
            else
            {
                return(View(model));
            }
        }