예제 #1
0
        public ActionResult Create([Bind(Include = "HeadsetID,Price,AvailableStoreID,HeadsetName")] VRHeadsetModels vRHeadsetModels)
        {
            if (ModelState.IsValid)
            {
                db.VRHeadsetModels.Add(vRHeadsetModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vRHeadsetModels));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "BundleID,HeadsetBundledID,BundledItem")] BundlesModels bundlesModels)
        {
            if (ModelState.IsValid)
            {
                db.BundlesModels.Add(bundlesModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bundlesModels));
        }
        public ActionResult Create([Bind(Include = "StoreID,StoreName")] StoresModels storesModels)
        {
            if (ModelState.IsValid)
            {
                db.StoresModels.Add(storesModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(storesModels));
        }
예제 #4
0
        public ActionResult Create([Bind(Include = "VehicleID,StudentID,Plate_number,Drivers_License,vehicle_front,vehicle_back,vehicle_side,Make,Color,proof_of_ownership,date_created,last_modified")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                db.Vehicles.Add(vehicle);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StudentID = new SelectList(db.Students, "StudentID", "Department", vehicle.StudentID);
            return(View(vehicle));
        }
예제 #5
0
        public ActionResult Create([Bind(Include = "StudentID,name,MatricNumber,StudentImage,ImageText,QrText,Department,Email,date_created,last_modified")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StudentID = new SelectList(db.QRCodes, "StudentID", "StudentID", student.StudentID);
            return(View(student));
        }
예제 #6
0
파일: BaseRepository.cs 프로젝트: HiepPP/VR
 public IEnumerable <T> Insert(IEnumerable <T> list)
 {
     using (var db = new VRContext())
     {
         using (var trans = db.Database.BeginTransaction())
         {
             IEnumerable <T> tList = null;
             try
             {
                 tList = db.Set <T>().AddRange(list);
                 db.SaveChanges();
                 trans.Commit(); //Data Saved Successfully. Transaction Commited
                                 //tList = list;
             }
             catch (DbException ex)
             {
                 Logger.Error(ex.Message, ex);
             }
             catch (Exception ex)
             {
                 trans.Rollback();//Error Occured during data saved. Transaction Rolled Back
                 Logger.Error(ex.Message, ex);
             }
             return(tList);
         }
     }
 }
예제 #7
0
        // Update status
        public bool UpdateStatus(int excelDetailId, int newStatus)
        {
            Logger.Info("Update status");
            bool check = false;

            try
            {
                using (var db = new VRContext())
                {
                    var exDetail = db.ExcelDetails.SingleOrDefault(x => x.Id == excelDetailId);
                    if (exDetail != null)
                    {
                        exDetail.TruckStatus = (TruckStatus)newStatus;
                        db.SaveChanges();
                        check = true;
                    }
                    else
                    {
                        check = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Info(ex.Message, ex);
            }

            return(check);
        }
예제 #8
0
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult Index(VerifyStudentshipViewModel VerifyStudentshipVM)
        //{
        //    TryValidateModel(VerifyStudentshipVM);
        //    if (ModelState.IsValid)
        //    {

        //    }
        //        return View(VerifyStudentshipVM);
        //}

        public async Task <JsonResult> GetStudentByMatricno(string matricno, string studentmail)
        {
            //db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Students]");

            if (matricno == null)
            {
                return(Json("Error 404"));
            }
            string value = string.Empty;

            Vehicle vehicle = db.Vehicles.Include("Student").Where(x => x.Student.MatricNumber.ToString() == matricno).FirstOrDefault();

            //List<Student>  student = repository.GetAll();
            //Student student = repository.GetByMatricNo(int.Parse(matricno));

            if (vehicle != null)
            {
                email = vehicle.Student.Email;
                if (vehicle.Student.StudentImage != null)
                {
                    vehicle.Student.ImageText = "data:image/png;base64," + Convert.ToBase64String(vehicle.Student.StudentImage, 0, vehicle.Student.StudentImage.Length, Base64FormattingOptions.None);
                    profileimage = vehicle.Student.ImageText;
                    regnumber    = vehicle.Student.StudentID;
                }

                value = JsonConvert.SerializeObject(vehicle, Formatting.Indented, new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });


                //Generate new Token
                string token = Helper.GenerateCode();

                //Generate new token details
                Token code = new Token();
                code.EmailAddress     = studentmail;
                code.VerificationCode = token;

                //Add token to database
                db.Tokens.Add(code);
                db.SaveChanges();

                //Send email now
                //await SendEmailTokenAsync(studentmail, token);
            }


            else
            {
                value = JsonConvert.SerializeObject(null, Formatting.Indented, new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });
                return(Json(value, JsonRequestBehavior.AllowGet));
            }

            return(Json(value, JsonRequestBehavior.AllowGet));
        }
예제 #9
0
 public ActionResult EditDisplay([Bind(Include = "HeadsetID,Price,AvailableStoreName,HeadsetName")] VRHeadsetModels vRHeadsetModels)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(vRHeadsetModels).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Unable to save changes. Try again, if the problem persists please contact your systems administrator.");
     }
     return(View(vRHeadsetModels));
 }
예제 #10
0
파일: BaseRepository.cs 프로젝트: HiepPP/VR
        public bool Update(List <T> dtoList)
        {
            using (var db = new VRContext())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    T entity = null;
                    try
                    {
                        var dbSet = db.Set <T>();
                        dtoList.ForEach(x =>
                        {
                            entity = dbSet.Find(x.Id);
                            if (entity != null)
                            {
                                db.Entry(entity).CurrentValues.SetValues(x);
                            }
                        });

                        db.SaveChanges();
                        trans.Commit();//Data Saved Successfully. Transaction Commited
                        return(true);
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                            }
                        }
                        return(false);
                    }
                    catch (DbException ex)
                    {
                        Logger.Error(ex.Message, ex);
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();//Error Occured during data saved. Transaction Rolled Back
                        Logger.Error(ex.Message, ex);
                        return(false);
                    }
                }
            }
        }
예제 #11
0
파일: BaseRepository.cs 프로젝트: HiepPP/VR
        public T Update(T dto)
        {
            T entity = null;

            try
            {
                using (var db = new VRContext())
                {
                    entity = db.Set <T>().Find(dto.Id);
                    if (entity != null)
                    {
                        db.Entry(entity).CurrentValues.SetValues(dto);
                        db.SaveChanges();
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
                entity = null;
            }
            catch (DbException ex)
            {
                Logger.Error(ex.Message, ex);
                entity = null;
            }
            catch (Exception ex)
            {
                entity = null;
                Logger.Error(ex.Message, ex);
            }

            return(entity);
        }
 public void SaveChanges()
 {
     context.SaveChanges();
 }
예제 #13
0
        public void AddingToD()
        {
            for (int i = 0; i < Node.Count; i++)
            {
                int     nrIn            = int.Parse(Node.Item(i).SelectSingleNode("nr").InnerText);
                int     artId           = int.Parse(Node.Item(i).SelectSingleNode("Artikelid").InnerText);
                int     varnummret      = int.Parse(Node.Item(i).SelectSingleNode("Varnummer").InnerText);
                string  namnPrimary     = Node.Item(i).SelectSingleNode("Namn").InnerText;
                string  namn2Seccondary = Node.Item(i).SelectSingleNode("Namn2").InnerText;
                decimal prisinklMomsen  = decimal.Parse(Node.Item(i).SelectSingleNode("Prisinklmoms").InnerText);
                int     panten          = 0;
                try
                {
                    panten = int.Parse(Node.Item(i).SelectSingleNode("Pant").InnerText);
                }
                catch (Exception)
                {
                }
                decimal  volymiMilliliter = decimal.Parse(Node.Item(i).SelectSingleNode("Volymiml").InnerText);
                decimal  prisPerLitern    = decimal.Parse(Node.Item(i).SelectSingleNode("PrisPerLiter").InnerText);
                DateTime saljstarten      = DateTime.ParseExact(Node.Item(i).SelectSingleNode("Saljstart").InnerText, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                bool     utgatt           = false;
                string   utgattstring     = Node.Item(i).SelectSingleNode("Utgått").InnerText;
                if (utgattstring == "1")
                {
                    utgatt = true;
                }
                string varugruppen = "";
                try
                {
                    varugruppen = Node.Item(i).SelectSingleNode("Varugrupp").InnerText;
                }
                catch (Exception)
                {
                }
                string typen         = Node.Item(i).SelectSingleNode("Typ").InnerText;
                string stilen        = Node.Item(i).SelectSingleNode("Stil").InnerText;
                string forpackningen = Node.Item(i).SelectSingleNode("Forpackning").InnerText;
                string forslutningen = Node.Item(i).SelectSingleNode("Forslutning").InnerText;
                string ursprunget    = Node.Item(i).SelectSingleNode("Ursprung").InnerText;
                string landet        = Node.Item(i).SelectSingleNode("Ursprunglandnamn").InnerText;
                string producenten   = "";
                try
                {
                    producenten = Node.Item(i).SelectSingleNode("Producent").InnerText;
                }
                catch (Exception)
                {
                }
                string leverantoren = "";
                try
                {
                    leverantoren = Node.Item(i).SelectSingleNode("Leverantor").InnerText;
                }
                catch (Exception)
                {
                }
                string argangenString = Node.Item(i).SelectSingleNode("Argang").InnerText;
                int    argangen       = 0;
                if (argangenString != "")
                {
                    argangen = int.Parse(Node.Item(i).SelectSingleNode("Argang").InnerText);
                }
                int provardargangen = 0;
                if (Node.Item(i).SelectSingleNode("Provadargang").InnerText != "")
                {
                    provardargangen = int.Parse(Node.Item(i).SelectSingleNode("Provadargang").InnerText);
                }
                string  alkoholString = Node.Item(i).SelectSingleNode("Alkoholhalt").InnerText;
                decimal alkoholhalten = 0;
                if (alkoholString.Contains('%'))
                {
                    alkoholhalten = decimal.Parse(alkoholString.Substring(0, alkoholString.Length - 1));
                }
                string sortimentet       = Node.Item(i).SelectSingleNode("Sortiment").InnerText;
                string sortimentetTexten = Node.Item(i).SelectSingleNode("SortimentText").InnerText;
                bool   ekolokiskt        = false;
                string ekostring         = Node.Item(i).SelectSingleNode("Ekologisk").InnerText;
                if (utgattstring == "1")
                {
                    utgatt = true;
                }
                bool etiskt = false;
                if (Node.Item(i).SelectSingleNode("Etiskt").InnerText == "1")
                {
                    utgatt = true;
                }
                bool koschert = false;
                if (Node.Item(i).SelectSingleNode("Koscher").InnerText == "1")
                {
                    utgatt = true;
                }
                string ravarorBeskrivningen = "";
                try
                {
                    ravarorBeskrivningen = Node.Item(i).SelectSingleNode("RavarorBeskrivning").InnerText;
                }
                catch (Exception)
                {
                }

                using (VRContext vRContext = new VRContext())
                {
                    try
                    {
                        var truncating = vRContext.SysSortTable.FromSql("TRUNCATE TABLE [SysSortTable]");
                    }
                    catch (Exception)
                    {
                    }

                    var addThis = new SysSortTable
                    {
                        Nr             = nrIn,
                        ArtikelId      = artId,
                        Varunummer     = varnummret,
                        Namn           = namnPrimary,
                        Namn2          = namn2Seccondary,
                        PrisInkMoms    = prisinklMomsen,
                        Pant           = panten,
                        VolymIml       = volymiMilliliter,
                        PrisPerLiter   = prisPerLitern,
                        Saljstart      = saljstarten,
                        Utgatt         = utgatt,
                        Varugrupp      = varugruppen,
                        Typ            = typen,
                        Stil           = stilen,
                        Forpackning    = forpackningen,
                        Forslutning    = forslutningen,
                        Ursprung       = ursprunget,
                        Land           = landet,
                        Producent      = producenten,
                        Leverantör     = leverantoren,
                        Argang         = argangen,
                        Provadarargang = provardargangen,
                        Alkoholhalt    = alkoholhalten,
                        Sortiment      = sortimentet,
                        SortimentText  = sortimentetTexten,
                        Ekolokisk      = ekolokiskt,
                        Etiskt         = etiskt,
                        Koscher        = koschert,
                        RavarorDesc    = ravarorBeskrivningen
                    };

                    vRContext.Add(addThis);
                    vRContext.SaveChanges();
                }
            }
        }