Ejemplo n.º 1
0
        public static void SendNewRequestExists(string reqbody, string sn)
        {
            var username = "";
            using(var db = new HTDBEnt())
            {
                username = db.HTDevices.Where(tf => tf.SN == sn).ToList().FirstOrDefault()?.HTUser?.AspNetUser?.Email;
            }
            string body =
                @" <div style=""border:groove; border-color:#373b41; "">
                    <div style=""background-color:#373b41"">
                        <div style=""float:left"">
                            <img src=""http://ht3-pro.com/Images/Email_Images/hitag_logo1.png"" width=""70"" height=""70"" />
                        </div>
                        <div style=""color:#ffffff; padding:30px;"">
                            HITAG SERVICE WEBSITE
                        </div>
                        <div style=""clear:both""></div>
                    </div>
                    <div style=""padding:15px;text-indent:25px;background-color:rgba(235, 238, 244, 0.49)"">
                        Ув.Администратор! Поступил запрос на ОБНОВЛЕНИЕ ЛИЦЕНЗИИ.
                        <hr />
                        Email/Логин:" + username + @"
                        <br /> Серийный номер: " + sn + @"
                        <hr />  This letter was sent automaticaly by robot and does not require an answer.
                        <pre>" + reqbody + @"<pre>
                    </div>
                    <div class=""BlokLink"" style=""background-color:#373b41; clear:both;  padding:10px;color:white"">
                        Перейти на сайт:<a href=""http://ht3-pro.com/"" style=""color:#ffffff"">ht3-pro.com</a>
                    </div>
                </div>";

            SendMessageToAdmin($"Hitag 3 service. New license request to {username} SN: {sn}", body);
        }
Ejemplo n.º 2
0
 public ActionResult GetSoftware()
 {
     var db = new HTDBEnt();
     Models.ViewModels.Admin.SoftwareVM mdl = new Models.ViewModels.Admin.SoftwareVM();
     mdl.SWARES = db.HTSoftwares.OrderByDescending(tf => tf.ReleaseDate).ToList();
     return PartialView(mdl);
 }
Ejemplo n.º 3
0
        public ActionResult AddProgrammer(string SN)
        {
            if(SN == null || SN.Length != 8)
            {
                return View("Error");
            }

            using(var db = new HTDBEnt())
            {
                var exists = db.HTDevices.FirstOrDefault(tf => tf.SN == SN.ToUpper());
                if(exists is HTDevice)
                    return View("Error");
                string userid = User.Identity.GetUserId();
                var currentuser = db.HTUsers.FirstOrDefault(tf => tf.AspNetUserId == userid);

                HTDevice dev = new HTDevice()
                {
                    SN = SN.ToUpper(),
                    AddDate = DateTime.Now,
                    OwnerID = currentuser.Id,
                    Locked = true
                };
                db.HTDevices.Add(dev);
                db.SaveChanges();
                MailManager.SendWhenUserAddNewDevice(SN, currentuser.AspNetUser.UserName);
            }

            return RedirectToAction("Index");
        }
Ejemplo n.º 4
0
 public FileContentResult FileDownload(int fileid)
 {
     using(var db = new HTDBEnt())
     {
         var userid = User.Identity.GetUserId();
         var htuser = db.HTUsers.FirstOrDefault(tf => tf.AspNetUserId == userid);
         if(!(htuser is HTUser)) return null;
         //  HTPerdeviceFile pdf = db.HTPerdeviceFiles.FirstOrDefault(tf=>tf.FileInStroreID==fileid&&tf.)
         //declare byte array to get file content from database and string to store file name
         byte[] fileData;
         string fileName;
         //create object of LINQ to SQL class
         var filedb = (from s in db.FilesStores where s.Id == fileid select s).ToList();
         if(filedb.Count > 0)
         {
             fileData = filedb[filedb.Count - 1].DATA;
             fileName = filedb[filedb.Count - 1].OriginalFileName;
             return File(fileData, "dump", fileName);
         }
         else return null;
     }
 }
Ejemplo n.º 5
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {



            if(ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };


                var result = await UserManager.CreateAsync(user, model.Password);
                if(result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    var htuser = new HTUser() { AspNetUserId = user.Id ,Locked = true, RegisterDate = DateTime.Now };
                    using(var db = new HTDBEnt())
                    {
                        using(var transaction = db.Database.BeginTransaction())
                        {
                            try
                            {
                                db.HTUsers.Add(htuser);
                                db.SaveChanges();
                                if(model.DeviceSN == null || model.DeviceSN.Length != 8)
                                {
                                    model.DeviceSN = "OOOOOOOO";
                                }
                                var RegDevice = new HTDevice() { SN = model.DeviceSN.ToUpper(), OwnerID = htuser.Id, Locked = true , AddDate  = DateTime.Now};
                                db.HTDevices.Add(RegDevice);
                                db.SaveChanges();
                                transaction.Commit();

                                MailManager.SendNewUserRegister(user.UserName, RegDevice.SN);

                            }
                            catch(Exception)
                            {
                                transaction.Rollback();
                            }


                          
                        }


                    }
                    // Дополнительные сведения о том, как включить подтверждение учетной записи и сброс пароля, см. по адресу: http://go.microsoft.com/fwlink/?LinkID=320771
                    // Отправка сообщения электронной почты с этой ссылкой
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Подтверждение учетной записи", "Подтвердите вашу учетную запись, щелкнув <a href=\"" + callbackUrl + "\">здесь</a>");

                    return RedirectToAction("Index", "Personal");
                }
                AddErrors(result);
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return View(model);
        }
Ejemplo n.º 6
0
        // GET: Personal
        public ActionResult Index()
        {
            PersonalOfficeViewModel mdl = new PersonalOfficeViewModel();
            string userid = User.Identity.GetUserId();
            using(var db = new HTDBEnt())
            {
                try
                {
                    var users = db.HTUsers.Where(tf => tf.AspNetUserId == userid).ToList();
                    if(users.Count == 0)
                        throw new Exception("User not found");
                    var htuser = users[0];
                    mdl.UserName = User.Identity.GetUserName();
                    mdl.UserLock = htuser.Locked == true ?
                        "Locked" : "OK";
                    mdl.RegisterDate = htuser.RegisterDate.ToString();

                    List<HTDevice> devices = db.HTDevices.Where(tf => tf.OwnerID == htuser.Id).ToList();

                    mdl.Devices = (from c in devices
                                   select new DevVM()
                                   {
                                       BLock = c.Locked,
                                       SN = c.SN,
                                       RegisterDate = c.AddDate?.ToString()
                                       ,
                                       Files = (from fileitem in db.HTPerdeviceFiles
                                                join ff in db.FilesStores on fileitem.FileInStroreID equals ff.Id
                                                where fileitem.DeviceID == c.Id
                                                select new PerDeviceFileVM() { Name = ff.OriginalFileName, ID = ff.Id }
                                             ).ToList()
                                   }).ToList();
                }
                catch(Exception)
                {

                    throw;
                }
            }
            return View(mdl);
        }