Example #1
0
        public Mobile GenerateToken(string imei, string idUsuario)
        {
            if (string.IsNullOrEmpty(imei))
            {
                throw new ArgumentNullException("O parâmetro imei passado está inválido.");
            }

            Mobile mobile = DbSet.FirstOrDefault(t => t.Imei == imei);

            if (mobile == null)
            {
                throw new Exception("MobileRepository.GenerateToken - Não foi encontrado o IMEI cadastrado na Base de dados.");
            }

            try
            {
                mobile.AuthToken = AESCrypt.Encrypt(idUsuario + ":" + Guid.NewGuid().ToString());
                mobile.IssuedOn  = DateTime.Now;
                mobile.ExpiresOn = DateTime.Now.AddMonths(1);

                //Criando o token
                DbSet.Attach(mobile);
                Context.Entry(mobile).State = EntityState.Modified;
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception("MobileRepository.GenerateToken - Erro ao gerar o Token para o IMEI: " + imei, ex);
            }

            return(mobile);
        }
Example #2
0
 public ActionResult Edit([Bind(Include = "Model,Price,CompanyId")] Mobiles mob)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mob).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", mob.CompanyId);
     return(View(mob));
 }
Example #3
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            //container.RegisterType<IPhone, Phone>();

            PhoneWindow phoneWindow = new PhoneWindow(new Phone());//container.Resolve<PhoneWindow>();//

            if (phoneWindow.ShowDialog() == true)
            {
                Phone phone = phoneWindow.PhoneModel;
                db.Phones.Add(phone);
                db.SaveChanges();
            }
        }
Example #4
0
 public string Buy(Order order)
 {
     if (ModelState.IsValid)
     {
         db.Orders.Add(order);
         // сохраняем в бд все изменения
         db.SaveChanges();
         return("Спасибо, " + order.User + ", за покупку!");
     }
     else
     {
         return("Nope");
     }
 }
Example #5
0
 public static void Initialize(MobileContext context)
 {
     if (!context.Phones.Any())
     {
         context.Phones.AddRange(
             new Phone
         {
             Name     = "Samsung Galaxy S8",
             Company  = "Samsung",
             Price    = 900,
             Features = "Операционная система    Android 7.0\nПамять 64 GB"
         },
             new Phone
         {
             Name     = "iPhone 8",
             Company  = "Apple",
             Price    = 1000,
             Features = "Операционная система    iOS\nПамять 128 GB"
         },
             new Phone
         {
             Name     = "Google Pixel 2",
             Company  = "Google",
             Price    = 950,
             Features = "Операционная система    Android 6.0\nПамять 32 GB"
         }
             );
         context.SaveChanges();
     }
     else
     {
         int a = 5;
         int b = 16;
         foreach (Phone phone in context.Phones)
         {
             if (phone.Company == "Apple")
             {
                 phone.Features = "Операционная система iOS" + " Память " + b + " GB";
             }
             else
             {
                 phone.Features = "Операционная система Android " + a + " Память " + b + " GB";
             }
             a++;
             b = b * 2;
         }
         context.SaveChanges();
     }
 }
        public void Save(Guild guild)
        {
            var curGuild = Db.Guilds.FirstOrDefault(_ => _.Id == guild.Id);

            if (curGuild == null)
            {
                Db.Guilds.Add(guild);
            }
            else
            {
                curGuild.Name = guild.Name;
            }

            Db.SaveChanges();
        }
 public void Initialize()
 {
     if (!db.Posts.Any())
     {
         db.Posts.AddRange(
             new Post {
             Topic = "Phones", Description = "Some data"
         },
             new Post {
             Topic = "Animals", Description = "Lorem ipsum"
         }
             );
         db.SaveChanges();
     }
 }
        public string Buy(Order order)
        {
            db.Orders.Add(order);
            db.SaveChanges();

            return($"Спасибо {order.User} за покуаку!");
        }
Example #9
0
        public static void Initialize(MobileContext mobilecontext)
        {
            if (!mobilecontext.Phones.Any())
            {
                mobilecontext.Phones.AddRange(
                    new Phone
                {
                    Name    = "iPhone XI",
                    Company = "Apple",
                    Price   = 1100
                },
                    new Phone
                {
                    Name    = "Samsung S20",
                    Company = "Samsung",
                    Price   = 850
                },
                    new Phone
                {
                    Name    = "Pixel 4",
                    Company = "Google",
                    Price   = 950
                }
                    );

                mobilecontext.SaveChanges();
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            PortConnect     port = new PortConnect();
            GeneralCommands gc   = new GeneralCommands(port);

            MobileContext db = new MobileContext();
            Phone         p  = new Phone {
                Company = "Xiaomi", Name = "BestPhone"
            };

            db.Phones.Add(p);
            db.SaveChanges();

            port.AddReceiver(gc.GeneralHandler);

            port.Connect();
            Console.WriteLine(port.IsConnected);

            if (port.IsConnected)
            {
                port.Operator();
            }

            Console.ReadLine();
        }
Example #11
0
 public string Buy(Order order)
 {
     db.Orders.Add(order);
     // save shanges
     db.SaveChanges();
     return("Thanks, " + order.User + ", for your order!");
 }
Example #12
0
        public List <LeaveApplDetails> RecomandationProcess(string employeecode, List <LeaveApplDetails> leaveappldetails)
        {
            try
            {
                List <LeaveApplDetails> prcoessemployess = new List <LeaveApplDetails>();
                using (MobileContext context = new MobileContext())
                {
                    foreach (var lvaply in leaveappldetails)
                    {
                        try
                        {
                            if (lvaply.Status == STATUS.CANCEL.ToString())
                            {
                                updateusedleaves(lvaply.EmpCode, lvaply.LeaveDays, context);
                            }
                            //lvaply.status = status.inprogress.tostring();
                            lvaply.RecommendedId   = employeecode;
                            lvaply.RecommendedName = getemployee(lvaply.RecommendedId)?.Name;
                            context.LeaveApplDetails.Update(lvaply);
                            if (context.SaveChanges() > 0)
                            {
                                prcoessemployess.Add(lvaply);
                            }
                        }
                        catch { }
                    }
                }

                return(prcoessemployess);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #13
0
 public static void Initialize(MobileContext context)
 {
     if (!context.Phones.Any())
     {
         context.Phones.AddRange(
             new Phone
         {
             Name    = "iPhone X",
             Company = "Apple",
             Price   = 600,
             Balance = 10
         },
             new Phone
         {
             Name    = "Samsung Galaxy Edge",
             Company = "Samsung",
             Price   = 550,
             Balance = 12
         },
             new Phone
         {
             Name    = "Pixel 3",
             Company = "Google",
             Price   = 500,
             Balance = 17
         }
             );
         context.SaveChanges();
     }
 }
Example #14
0
 public IActionResult Buy(Order order)
 {
     db.Orders.Add(order);
     db.SaveChanges();
     ViewBag.User = order.User;
     return(View("Result"));
 }
Example #15
0
        public ActionResult MakeOrder(OrderViewModel orderModel)
        {
            if (ModelState.IsValid)
            {
                Phone phone = db.Phones.Find(orderModel.PhoneId);
                if (phone == null)
                {
                    return(HttpNotFound());
                }
                decimal sum = phone.Price;

                // если сегодня первое число месяца, тогда скидка в 10%
                if (DateTime.Now.Day == 1)
                {
                    sum = sum - sum * 0.1m;
                }

                Order order = new Order
                {
                    PhoneId     = phone.Id,
                    PhoneNumber = orderModel.PhoneNumber,
                    Address     = orderModel.Address,
                    Date        = DateTime.Now,
                    Sum         = sum
                };
                db.Orders.Add(order);
                db.SaveChanges();
                return(Content("<h2>Ваш заказ успешно оформлен</h2>"));
            }
            return(View(orderModel));
        }
Example #16
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MobileContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MobileContext> >()))
            {
                // Look for any movies.
                if (context.TaiKhoanAdmin.Any())
                {
                    return;   // DB has been seeded
                }

                context.TaiKhoanAdmin.AddRange(
                    new TaiKhoanAdmin
                {
                    User        = "******",
                    Pass        = MD5.GetMD5("SuperAdmin"),
                    Name        = "Phạm Toàn Trung",
                    Email       = "*****@*****.**",
                    PhoneNumber = "0947902015",
                    Role        = "Super Admin",
                    TrangThai   = true
                }
                    );
                context.SaveChanges();
            }
        }
        public IActionResult Order(int phone_id, string user, string address, string phone)
        {
            var result = new object();

            if (phone_id != 0 && phone != null)
            {
                Order order = new Order()
                {
                    PhoneId      = phone_id,
                    User         = user,
                    Address      = address,
                    ContactPhone = phone,
                    DateTime     = DateTime.Now
                };
                _context.Add(order);
                _context.SaveChanges();
                result = new { message = "success" };
            }
            else
            {
                result = new { message = "error" };
            }

            return(Ok(result));
        }
Example #18
0
 public string Buy(Order order)
 {
     db.Orders.Add(order);
     // сохраняем в бд все изменения
     db.SaveChanges();
     return("Thanks, " + order.User + "!");
 }
        public string Buy(Order order)
        {
            db.Orders.Add(order);
            db.SaveChanges();

            return("Спасибо, " + order.User + ", за покупку!");
        }
Example #20
0
        public void updateusedleaves(string empcode, double?noofleaves, MobileContext context, bool isLeaveCanceled = false)
        {
            try
            {
                var leavebalancemaster = context.LeaveBalanceMaster.Where(x => x.UserId == empcode).FirstOrDefault();

                if (isLeaveCanceled)
                {
                    leavebalancemaster.Used    -= noofleaves;
                    leavebalancemaster.Balance += noofleaves;
                }
                else
                {
                    leavebalancemaster.Used    += noofleaves;
                    leavebalancemaster.Balance -= noofleaves;
                }

                context.LeaveBalanceMaster.Update(leavebalancemaster);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #21
0
 public IActionResult Buy(Order order)
 {
     db.Orders.Add(order);
     db.SaveChanges();
     ViewBag.stringd = "Спасибо, " + order.User + ", за покупку!";
     return(View());
 }
Example #22
0
        public ActionResult Create([Bind(Include = "BrandId,BrandName")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                if (CanAddBrand(brand.BrandName))
                {
                    db.Brands.Add(brand);
                    db.SaveChanges();
                    TempData["BrandStatusMessage"] = "Brand has been added successfully!";
                    return(RedirectToAction("Index"));
                }
                DisplayBrandExistsMessage(brand);
            }

            return(View(brand));
        }
Example #23
0
        public HomeController(MobileContext context)
        {
            this.db = context;
            // добавляем начальные данные
            if (db.Companies.Count() == 0)
            {
                Company oracle = new Company {
                    Name = "Oracle"
                };
                Company google = new Company {
                    Name = "Google"
                };
                Company microsoft = new Company {
                    Name = "Microsoft"
                };
                Company apple = new Company {
                    Name = "Apple"
                };



                db.Companies.AddRange(oracle, microsoft, google, apple);
                db.Mobiles.AddRange();
                db.SaveChanges();
            }
        }
Example #24
0
        public Companies InsertCompanies(Companies companies, out string errorMessage)
        {
            try
            {
                errorMessage = string.Empty;

                using (MobileContext context = new MobileContext())
                {
                    var _code = context.Companies.Max(x => x.CompanyCode) ?? "0";

                    companies.CompanyCode = (Convert.ToInt32(_code) + 1).ToString();
                    companies.Active      = "Y";
                    companies.AddDate     = DateTime.Now;

                    context.Add(companies);
                    if (context.SaveChanges() > 0)
                    {
                        return(companies);
                    }

                    errorMessage = "failed to create client.";
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #25
0
        public static void Initialize(MobileContext context)
        // public static void Initialize(IServiceProvider serviceProvider)
        {
            // var context = serviceProvider.GetService(typeof(MobileContext)) as MobileContext;

            if (!context.Phones.Any())
            {
                context.Phones.AddRange(
                    new Phone
                {
                    Name    = "iPhone X",
                    Company = "Apple",
                    Price   = 600
                },
                    new Phone
                {
                    Name    = "Samsung Galaxy Edge",
                    Company = "Samsung",
                    Price   = 550
                },
                    new Phone
                {
                    Name    = "Pixel 3",
                    Company = "Google",
                    Price   = 500
                }
                    );
                context.SaveChanges(); //сохраняем БД
            }
        }
Example #26
0
 public IActionResult AddAccessoryItem([FromBody] List <AccessoryItems> accessory)
 {
     try
     {
         for (var i = 0; i < accessory.ToArray().Length; i++)
         {
             _context.AccessoryItems.Add(accessory[i]);
         }
         _context.SaveChanges();
         return(CreatedAtAction("GetAccessoryItems", accessory));
     }
     catch
     {
         return(BadRequest());
     }
 }
Example #27
0
 public string Buy(Order order)
 {
     db.Orders.Add(order);
     // сохраняем в бд все изменения
     db.SaveChanges();
     return("Спасибо, " + order.User + ", за покупку!");
 }
Example #28
0
 public static void Initializze(MobileContext context)
 {
     if (!context.Phones.Any())
     {
         context.Phones.AddRange(
             new Phone
         {
             Name    = "Honor 9 Lite",
             Company = "Huawei",
             Price   = 15000
         },
             new Phone
         {
             Name    = "Iphone 10",
             Company = "Apple",
             Price   = 87000
         },
             new Phone
         {
             Name    = "Zeon Empress",
             Company = "Vertex",
             Price   = 3700
         }
             );
         context.SaveChanges();
     }
 }
 public static void Initialize(MobileContext context)
 {
     if (!context.Phones.Any())
     {
         context.Phones.AddRange(
             new Phone
             {
                 Name = "iPhone X",
                 Company = "Apple",
                 Price = 1000
             },
             new Phone
             {
                 Name = "Samsung Galaxy Edge",
                 Company = "Samsung",
                 Price = 550
             },
             new Phone
             {
                 Name = "Lumia 950",
                 Company = "Microsoft",
                 Price = 500
             }
          );
         context.SaveChanges();
     }
 }
Example #30
0
        public List <TourAdvance> TourApprovalProcess(string empcode, List <TourAdvance> toursList)
        {
            try
            {
                List <TourAdvance> processToures = new List <TourAdvance>();
                using (MobileContext context = new MobileContext())
                {
                    foreach (var tours in toursList)
                    {
                        tours.ApprovedBy = empcode;
                        context.TourAdvance.Update(tours);
                        if (context.SaveChanges() > 0)
                        {
                            processToures.Add(tours);
                        }
                    }
                }

                return(processToures);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }