コード例 #1
0
        public void Db_UpdateCustomer()
        {
            // arrange
            var customerDb = new CustomerDb(_connectionString);
            var customer   = new Customer.EF.Customer {
                Id = 0, FirstName = "Marli", LastName = "Smith", Password = "******"
            };

            // act
            customer           = customerDb.AddCustomer(customer);
            customer.FirstName = "Marlo";
            customer           = customerDb.UpdateCustomer(customer);

            // assert
            Assert.AreEqual(customer.FirstName, "Marlo");
        }
コード例 #2
0
        public ActionResult DeleteCustomer(int id, FormCollection collection)
        {
            CustomerDb dbCustomer = new CustomerDb();
            bool       customerValid;

            customerValid = dbCustomer.DeleteCustomer(id);

            if (customerValid)
            {
                return(RedirectToAction("Customers"));
            }
            else
            {
                return(RedirectToAction("DeleteCustomer", id));
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: copley/CSharpTips
        private static void Main()
        {
            //var f = new Form1();
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            var lr =
                new LocalReport();

            string deviceInfo =
                "<DeviceInfo>" +
                "<SimplePageHeaders>True</SimplePageHeaders>" +
                "</DeviceInfo>";

            lr.ReportPath = @"Report1.rdlc";

            CustomerDb db   = CustomerDb.Create();
            Customer   cust = db.Customers[0];
            var        ds1  = new ReportDataSource
            {
                DataSourceId = "DataModel_Customer",
                DataMember   = "DataModel_Customer",
                Name         = "DataModel_Customer"
            };

            lr.DataSources.Add(ds1);
            lr.DataSources.Add(new ReportDataSource("DataModel_Order"));


            string mimeType;
            string encoding;
            string fileNameExtension;

            string[]  streams;
            Warning[] warnings;
            byte[]    bytes = lr.Render("PDF", deviceInfo,
                                        out mimeType,
                                        out encoding, out fileNameExtension,
                                        out streams,
                                        out warnings);

            using (var fs = new FileStream(@"Report.pdf", FileMode.Create)) {
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();
            }
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: eartru/videorama
        /// <summary>
        /// Show view to edit password current account
        /// </summary>
        /// <returns>View|Redirect</returns>
        public ActionResult EditPassword()
        {
            CustomerDb dbCustomer    = new CustomerDb();
            var        claimIdentity = User.Identity as ClaimsIdentity;
            int        id            = Convert.ToInt32(claimIdentity.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (id > 0)
            {
                PasswordViewModel passwordViewModel = new PasswordViewModel
                {
                    IdUser = id
                };

                return(View(passwordViewModel));
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #5
0
        // GET: Clients/Remove/5
        public ActionResult Remove(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerDb customerDb = _db.Customers.Find(id);

            if (customerDb == null)
            {
                return(HttpNotFound());
            }

            Customer customer = JsonConvert.DeserializeObject <Customer>(customerDb.Obj_Data);

            customer.Id = (int)id;
            return(View(customer));
        }
コード例 #6
0
        public int Save(Customer customer, CustomerDb db)
        {
            if (IsDbContextNull(db) || IsCustomerNull(customer))
            {
                return(0);
            }

            db.Customers.Add(customer);
            try
            {
                db.SaveChanges();
                return(customer.Id);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error occurred while saving customer{(_logSensitiveData ? JsonConvert.SerializeObject(customer) : "")}");
                return(0);
            }
        }
コード例 #7
0
        public ActionResult Register(Customer customer)
        {
            if (ModelState.IsValid)
            {
                CustomerDb dbCustomer = new CustomerDb();
                bool       isCustomerCreated;
                isCustomerCreated = dbCustomer.AddCustomer(customer);

                if (isCustomerCreated)
                {
                    return(RedirectToAction("Login", "Authentication"));
                }

                return(RedirectToAction("Register", "Authentication"));
            }
            else
            {
                return(View());
            }
        }
コード例 #8
0
        public Customer GetById(int id, CustomerDb db)
        {
            if (IsDbContextNull(db))
            {
                return(null);
            }

            try
            {
                Customer customer = db.Customers.SingleOrDefault(c => c.Id == id);
                if (customer == null)
                {
                    _logger.LogDebug($"No customer found for id: {id}");
                }
                return(customer);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error occurred while getting customer by id{(_logSensitiveData ? "{" + id + "}" : "")}");
                return(null);
            }
        }
コード例 #9
0
        public int UpdatePartial(int id, dynamic customer, CustomerDb db)
        {
            if (IsDbContextNull(db))
            {
                return(0);
            }

            Customer trackedCustomer = null;

            try
            {
                trackedCustomer = db.Customers.SingleOrDefault(c => c.Id == id);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error occurred while getting customer by id{(_logSensitiveData ? "{" + id + "}" : "")} for partial update");
            }

            if (trackedCustomer == null)
            {
                _logger.LogDebug($"No customer found for given id{(_logSensitiveData ? "{" + id + "}" : "")}");
                return(0);
            }

            if (customer.GetType().GetProperty("Id") != null)
            {
                customer.Id = id;                 //cannot update the id
            }
            try
            {
                db.Entry(trackedCustomer).CurrentValues.SetValues(customer);
                return(db.SaveChanges());
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error occurred while partially updating customer{(_logSensitiveData ? JsonConvert.SerializeObject(customer, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }) : " ")}");
                return(0);
            }
        }
コード例 #10
0
ファイル: AccountController.cs プロジェクト: eartru/videorama
        public ActionResult Edit(AccountViewModel customerViewModel)
        {
            if (ModelState.IsValid)
            {
                CustomerDb dbCustomer = new CustomerDb();
                bool       isCustomerEdited;

                Customer customer = new Customer
                {
                    IdUser     = customerViewModel.IdUser,
                    FirstName  = customerViewModel.FirstName,
                    LastName   = customerViewModel.LastName,
                    Address    = customerViewModel.Address,
                    PostalCode = customerViewModel.PostalCode,
                    Town       = customerViewModel.Town,
                    Country    = customerViewModel.Country,
                    Email      = customerViewModel.Email,
                    Username   = customerViewModel.Username
                };

                isCustomerEdited = dbCustomer.UpdateCustomer(customer);

                if (isCustomerEdited)
                {
                    var claimIdentity = User.Identity as ClaimsIdentity;
                    int id            = Convert.ToInt32(claimIdentity.FindFirst(ClaimTypes.NameIdentifier).Value);
                    if (id > 0)
                    {
                        return(RedirectToAction("Detail", "Account"));
                    }

                    return(RedirectToAction("Index", "Home"));
                }

                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #11
0
        /// <summary>
        /// Send json request to check a user in DB exist with this email
        /// </summary>
        /// <param name="Email"></param>
        /// <returns>Json</returns>
        public JsonResult IsEmailExist(string Email, int?IdUser)
        {
            UserDb dbUser    = new UserDb();
            User   userFound = new User();

            userFound = dbUser.GetUserByEmail(Email);
            int        id            = 0;
            string     email         = "";
            CustomerDb dbCustomer    = new CustomerDb();
            var        claimIdentity = User.Identity as ClaimsIdentity;

            if (claimIdentity.GetUserId() != null)
            {
                id    = Convert.ToInt32(claimIdentity.FindFirst(ClaimTypes.NameIdentifier).Value);
                email = Convert.ToString(claimIdentity.FindFirst(ClaimTypes.Email).Value);
            }

            // Check if the  account is the same of account edited by the admin
            if (IdUser != null && userFound.IdUser == IdUser)
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            // Check if the edit email is the same of the connected account
            if (id > 0 && userFound.Email == email)
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            if (userFound.Username != null)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #12
0
        public int UpdateFull(int id, Customer customer, CustomerDb db)
        {
            if (IsDbContextNull(db) || IsCustomerNull(customer))
            {
                return(0);
            }

            Customer trackedCustomer = null;

            try
            {
                trackedCustomer = db.Customers.SingleOrDefault(c => c.Id == id);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error occurred while getting customer by id{(_logSensitiveData ? "{" + id + "}" : "")} for full update");
                return(0);
            }

            if (trackedCustomer == null)
            {
                _logger.LogDebug($"No customer found for given id{(_logSensitiveData ? "{" + id + "}" : "")}");
                return(0);
            }

            customer.Id = id;               //avoid updating the id
            try
            {
                db.Entry(trackedCustomer).CurrentValues.SetValues(customer);
                return(db.SaveChanges());
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error occurred while fully updating customer{(_logSensitiveData ? JsonConvert.SerializeObject(customer) : "")}");
                return(0);
            }
        }
コード例 #13
0
 public CustomerBaseBusiness()
 {
     customerDb     = new CustomerDb();
     customerTypeDb = new CustomerTypeDb();
 }
コード例 #14
0
        public CustomerController()
        {
            CustomerContextFactory factory = new CustomerContextFactory();

            _db = factory.Create();
        }
コード例 #15
0
 public CustomerRepository(CustomerDb context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
コード例 #16
0
 public CustomerBL()
 {
     customerDb = new CustomerDb();
 }
コード例 #17
0
 public void Fill() => customers = CustomerDb.GetCustomers();
コード例 #18
0
        // GET: Customer
        public ActionResult Index()
        {
            var customers = CustomerDb.GetAll();

            return(View(customers));
        }
コード例 #19
0
 public void Save() => CustomerDb.SaveCustomers(customers);
コード例 #20
0
        // GET: Customer
        public ActionResult Index()
        {
            var customers = CustomerDb.GetAllCustomers();

            return(Json(customers));
        }
コード例 #21
0
 public static void AddReference(string keyName, CustomerDb cdb)
 {
     ReferenceHolder.Add(keyName, cdb);
 }
コード例 #22
0
        public IActionResult GetAll([FromQuery] Page page, [FromQuery] CustomerFilter filter, [FromServices] CustomerDb db)
        {
            if (page == null || page.PageNo < 1 || page.PageSize < 1)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, new { error = "invalid page details" }));
            }

            return(Ok(_dao.GetAll(page, filter, db)));
        }
コード例 #23
0
        public ActionResult Delete(int Id)
        {
            var customerInDb = CustomerDb.GetById(Id);

            return(View(customerInDb));
        }
コード例 #24
0
 public CustomerBs()
 {
     CustomerDb = new CustomerDb();
 }