Exemplo n.º 1
0
 public async Task <ActionResult <IEnumerable <Cart> > > GetTotalOrder(int cartId, string BuyrId)
 {
     try
     {
         var cart = _context.Cart.FirstOrDefault(s => s.CartId.Equals(cartId));
         cart.Status = "U";
         _context.Entry(cart).Property("Status").IsModified = true;
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateException /* ex */)
     {
         //Log the error (uncomment ex variable name and write a log.
         ModelState.AddModelError("", "Unable to save changes. " +
                                  "Try again, and if the problem persists " + "see your system administrator.");
     }
     return(await _context.Cart
            .Where(a => a.Status == "U" && a.BuyrID == BuyrId)
            .Include(vehicle => vehicle.AutosVehicle)
            .ThenInclude(make => make.CarMake)
            .Include(vehicle => vehicle.AutosVehicle)
            .ThenInclude(model => model.CarModel)
            .Include(vehicle => vehicle.AutosVehicle)
            .ThenInclude(carbody => carbody.CarBody)
            .ToListAsync());
 }
        public PartialViewResult Edit([Bind(Include = "Id,Description,Options,ExamId")] SingleSelectionQuestionWithOptionsViewModel model)
        {
            if (ModelState.IsValid)
            {
                SingleSelectionQuestion question = new SingleSelectionQuestion
                {
                    Id          = model.Id,
                    ExamId      = model.ExamId,
                    Description = model.Description,
                    Options     = model.Options
                };

                _db.Entry(question).State = EntityState.Modified;
                foreach (var option in question.Options)
                {
                    _db.Entry(option).State = EntityState.Modified;
                }

                _db.SaveChanges();

                question = _db.SingleSelectionQuestions.Include(q => q.Variables).Single(q => q.Id == question.Id);
                var evaluator = new NotationlessEvaluator();
                question = evaluator.Evaluate(question) as SingleSelectionQuestion;
                return(PartialView("_Details", question));
            }

            return(PartialView("_Edit", model));
        }
Exemplo n.º 3
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (Context.Entry(entityToDelete).State == EntityState.Detached)
     {
         DbSet.Attach(entityToDelete);
     }
     DbSet.Remove(entityToDelete);
 }
Exemplo n.º 4
0
        /// <inheritdoc />
        public async Task <SiteDTO> SaveAsync(SiteDTO model)
        {
            if (model == null)
            {
                throw new ArgumentException("Передана пустая объектная модель.");
            }

            EntityEntry <SiteStatus> siteStatusEntry = null;
            Guid id;
            var  site = await Context.Sites.Select(x => x)
                        .FirstOrDefaultAsync(x => x.Id == model.Id);

            if (site != null)
            {
                var siteEntry = Context.Entry(site);
                siteEntry.CurrentValues.SetValues(model);
                siteEntry.State = EntityState.Modified;

                var siteStatus = await Context.SiteStatuses.Select(x => x)
                                 .FirstOrDefaultAsync(x => x.Site.Id == model.Id);

                siteStatusEntry = Context.Entry(siteStatus);
                siteStatusEntry.Entity.CheckedInterval = model.CheckedInterval;
                siteStatusEntry.State = EntityState.Modified;
                id = site.Id;
            }
            else
            {
                var siteEntry = await Context.Sites.AddAsync(model.ToSite());

                if (siteEntry != null)
                {
                    var siteStatus = new SiteStatus
                    {
                        Site            = siteEntry.Entity,
                        CheckedInterval = model.CheckedInterval == 0 ? 5 : model.CheckedInterval
                    };
                    siteStatusEntry = await Context.SiteStatuses.AddAsync(siteStatus);
                }
                id = siteEntry.Entity.Id;
            }

            if (siteStatusEntry != null)
            {
                await this.UpdateStatusFields(model, siteStatusEntry);
            }

            await Context.SaveChangesAsync();

            return(await GetAsync(id));
        }
Exemplo n.º 5
0
        public ActionResult Index(RequestSite site)
        {
            if (!String.IsNullOrEmpty(site.SiteName))
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(site.SiteName);

                Stopwatch sw = new Stopwatch();
                sw.Start();

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                response.Close();

                sw.Stop();

                site = new RequestSite
                {
                    SiteName    = site.SiteName,
                    RequetsTime = sw.Elapsed.Milliseconds
                };


                context.Entry(site).State = EntityState.Added;
                context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 6
0
        public async Task <Element> PutElement([FromRoute] int id, [FromBody] Element element)
        {
            _context.Entry(element).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(_context.Elements.Single(e => e.ElementId == id));
        }
        public JsonResult AddOrUpdateLesson(int day, int lesson, string subject, int TeacherId)
        {
            int    TimetableId = (int)Session["TimeTableId"];
            Lesson find        = db.Lessons.Where(s => s.TimetableId == TimetableId).
                                 Where(s => s.day == day).Where(s => s.number == lesson).FirstOrDefault();

            if (find == null)
            {
                Lesson ls = new Lesson();
                ls.day    = day;
                ls.number = lesson;
                ls.name   = subject;
                Teacher teacher = db.Teachers.Find(TeacherId);
                ls.TeachersName = teacher.LastName + " " + teacher.FirstName[0] + "." + teacher.FathersName[0] + ".";
                ls.TimetableId  = (int)Session["TimeTableId"];
                db.Lessons.Add(ls);
            }
            else
            {
                Teacher teacher = db.Teachers.Find(TeacherId);
                find.TeachersName = teacher.LastName + " " + teacher.FirstName[0] + "." + teacher.FathersName[0] + ".";
                find.name         = subject;
                db.Lessons.Attach(find);
                db.Entry(find).State = EntityState.Modified;
            }
            db.SaveChanges();
            return(Json(true));
        }
        public async Task <IActionResult> PutOrderMaster(int id, OrderMaster orderMaster)
        {
            if (id != orderMaster.INVNUM)
            {
                return(BadRequest());
            }

            _context.Entry(orderMaster).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderMasterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutSiteUsers(string id, SiteUsers siteUsers)
        {
            if (id != siteUsers.UserId)
            {
                return(BadRequest());
            }

            _context.Entry(siteUsers).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SiteUsersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 10
0
        public async Task <IActionResult> PutAutosVehicle(int id, AutosVehicle autosVehicle)
        {
            if (id != autosVehicle.AutoId)
            {
                return(BadRequest());
            }

            _context.Entry(autosVehicle).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AutosVehicleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 11
0
        public async Task <ActionResult <Character> > PutFilter([FromRoute] int id, [FromBody] Filter filter)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != filter.FilterId)
            {
                return(BadRequest());
            }

            _context.Entry(filter).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FilterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(_context.Character.Single(r => r.CharacterId == filter.CharacterId));
        }
        public ActionResult EditSite(Site site)
        {
            db.Entry(site).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> PutConference([FromRoute] int id, [FromBody] Conference conference)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != conference.ConferenceID)
            {
                return(BadRequest());
            }

            _context.Entry(conference).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ConferenceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutAutosBuyer(string id, AutosBuyer autosBuyer)
        {
            if (id != autosBuyer.BuyrID)
            {
                return(BadRequest());
            }

            _context.Entry(autosBuyer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AutosBuyerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public string this[string key]
        {
            get
            {
                if (_cache[key] != null)
                {
                    return(_cache[key] as string);
                }

                return(_db.Settings.Find(key)?.Value);
            }
            set
            {
                var setting = _db.Settings.Find(key);
                if (setting == null)
                {
                    setting = new Setting {
                        Id = key, Value = value
                    };
                    _db.Settings.Add(setting);
                    _db.SaveChanges();
                }
                else
                {
                    setting.Value            = value;
                    _db.Entry(setting).State = EntityState.Modified;
                    _db.SaveChanges();
                }

                _cache[key] = setting.Value;
            }
        }
Exemplo n.º 16
0
        public async Task <IActionResult> PutCarModel(string id, CarModel carModel)
        {
            if (id != carModel.ModlId)
            {
                return(BadRequest());
            }

            _context.Entry(carModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 17
0
        public void Update(TEntity entity, params object[] keyValues)
        {
            Expect.ArgumentNotNull(entity);
            var contextEntry = Context.Entry(entity);

            if (contextEntry != null)
            {
                var oldEntity = Context.Set <TEntity>().Find(keyValues);
                if (oldEntity != null)
                {
                    var contextOldEntry = Context.Entry(oldEntity);
                    contextOldEntry.CurrentValues.SetValues(entity);
                    contextOldEntry.State = EntityState.Modified;
                    Context.SaveChanges();
                }
            }
        }
        public void SaveQuestion(QuestionWithOptionsViewModel model)
        {
            MultipleSelectionQuestion question = new MultipleSelectionQuestion
            {
                Id          = model.Id,
                ExamId      = model.ExamId,
                Description = model.Description,
                Options     = model.Options
            };

            _db.Entry(question).State = EntityState.Modified;
            foreach (var option in question.Options)
            {
                _db.Entry(option).State = EntityState.Modified;
            }

            _db.SaveChanges();
        }
Exemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "ID,Name,Description")] DocumentType documentType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(documentType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(documentType));
 }
Exemplo n.º 20
0
 public ActionResult Edit([Bind(Include = "UserID,LName,FName,CmtCount,SubDate")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Exemplo n.º 21
0
 public ActionResult Edit([Bind(Include = "ID,EventTitle,Description,Cost,Location")] Event @event)
 {
     if (ModelState.IsValid)
     {
         db.Entry(@event).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(@event));
 }
Exemplo n.º 22
0
 public ActionResult Edit([Bind(Include = "ID,ProjectTitle,Description,Requirements,Location")] Project project)
 {
     if (ModelState.IsValid)
     {
         db.Entry(project).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(project));
 }
Exemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "ProductId,Title,Author,Price,Description,genre,Image,publisher")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(book));
 }
Exemplo n.º 24
0
 public ActionResult Edit([Bind(Include = "Id,LastName,FirstMidName,StreetAddress,Suburb,City,PostalCode")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Exemplo n.º 25
0
 public ActionResult Edit(Clients clients)
 {
     if (ModelState.IsValid)
     {
         db.Entry(clients).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(clients));
 }
Exemplo n.º 26
0
 public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,EnrollmentDate,Permission")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Exemplo n.º 27
0
 public ActionResult Edit([Bind(Include = "ID,name,short_description,description,img_url,repo_url,target_url")] Project project)
 {
     if (ModelState.IsValid)
     {
         db.Entry(project).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(project));
 }
Exemplo n.º 28
0
 public ActionResult Edit([Bind(Include = "Id,name,begin,end")] Period period)
 {
     if (ModelState.IsValid)
     {
         db.Entry(period).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(period));
 }
Exemplo n.º 29
0
        public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,FathersName,Email")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Entry(student).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", (int)Session["GroupId"]));
            }

            return(View(student));
        }
        public ActionResult Edit([Bind(Include = "Email,Role,FirstName,LastName,Password,DateOfBirth,Gender,Interest,Facility,Liking")] User user)
        {
            if (ModelState.IsValid)
            {
                _db.Entry(user).State = EntityState.Modified;
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }