Exemple #1
0
        public async Task <int> RemoveByAsync(TEntity tentity)
        {
            var entity = _dbContext.Entry(tentity);

            if (tentity != null)
            {
                entity.State = EntityState.Modified;
                entity.Property("IsDel").IsModified        = true;
                entity.Property("DeleteUserId").IsModified = true;
                entity.Property("DeleteDate").IsModified   = true;
                await UpdateByAsync(tentity);
            }
            return(await _dbContext.SaveChangesAsync());
        }
Exemple #2
0
        public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != category.CategoryId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemple #3
0
        public async Task <ActionResult <Branch> > PutBranchItem(int branchId, Branch Branch)
        {
            if (branchId != Branch.BranchId)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!Branch(branchId))
                //{
                //    return NotFound();
                //}
                //else
                //{
                //    throw;
                //}
            }

            return(NoContent());
        }
Exemple #4
0
        public async Task <IActionResult> PutTheme([FromRoute] int id, [FromBody] Theme theme)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != theme.themeId)
            {
                return(BadRequest());
            }

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

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

            APIReturn re = new APIReturn();

            re.Status = "success";
            return(Ok(re));
        }
 public ActionResult Edit([Bind(Include = "Sch_Id,Departure_Location,Arrival_Location,Dept_DateTime,Arrvl_DateTime,Ship_Id")] Schedule_tbl schedule_tbl)
 {
     if (ModelState.IsValid)
     {
         if (checkSchedule(schedule_tbl) == true)
         {
             Schedule_tbl targetSchedule = db.Schedule_tbl.Find(schedule_tbl.Sch_Id);
             targetSchedule.Arrival_Location    = schedule_tbl.Arrival_Location;
             targetSchedule.Arrvl_DateTime      = schedule_tbl.Arrvl_DateTime;
             targetSchedule.Departure_Location  = schedule_tbl.Departure_Location;
             targetSchedule.Dept_DateTime       = schedule_tbl.Dept_DateTime;
             targetSchedule.Ship_Id             = schedule_tbl.Ship_Id;
             targetSchedule.Available_Container = db.Ship_tbl.Find(targetSchedule.Ship_Id).Container_Limit;
             db.Entry(targetSchedule).State     = EntityState.Modified;
             db.SaveChanges();
             TempData["message"] = "Schedule has been edited!";
             return(RedirectToAction("ScheduleManagement"));
         }
         else
         {
             ViewBag.PortLocation = getLocation();
             ViewBag.ShipList     = getShips();
             return(View());
         }
     }
     return(View(schedule_tbl));
 }
Exemple #6
0
 public ActionResult Edit([Bind(Include = "EventCatID,Name,Outdoor,Family")] EventCategory eventCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(eventCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(eventCategory));
 }
Exemple #7
0
 public ActionResult Edit([Bind(Include = "Id,ProjectName,ProjectDesc,ProjectImage,PostedOn")] Project project)
 {
     if (ModelState.IsValid)
     {
         db.Entry(project).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(project));
 }
Exemple #8
0
 public ActionResult Edit([Bind(Include = "PageId,PageName,PagePosition,PageVisible,PageContent")] Page page)
 {
     if (ModelState.IsValid)
     {
         db.Entry(page).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(page));
 }
Exemple #9
0
 public ActionResult Edit([Bind(Include = "Id,Title,Content,Created,Published,UrlImage,CombinedTags")] Post post)
 {
     if (ModelState.IsValid)
     {
         db.Entry(post).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(post));
 }
 public ActionResult Edit([Bind(Include = "SubjectId,SubjectName,SubjectPosition,SubjectVisible")] Subject subject)
 {
     if (ModelState.IsValid)
     {
         db.Entry(subject).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(subject));
 }
 public ActionResult Edit([Bind(Include = "Id,Username,Password,Email,FirstName,LastName,About,Avatar,Location,Phone,RegisteredOn,IsAdmin")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction(user.Username, "User"));
     }
     return(View(user));
 }
 public ActionResult Edit(ShopModel shopModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shopModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(shopModel));
 }
        public async Task <ActionResult> Edit([Bind(Include = "ID,FirstName,LastName,EmailAddress,Birthdate,NumberOfComputers")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Entry(contact).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(contact));
        }
Exemple #14
0
        public async Task <ActionResult> Edit([Bind(Include = "LocationID,LAT,LONG,Name")] Location location)
        {
            if (ModelState.IsValid)
            {
                db.Entry(location).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(location));
        }
Exemple #15
0
 public ActionResult Edit([Bind(Include = "Cust_Id,Cust_Name,Cust_Contact,Cust_EmailAddress,Cust_Address")] Customer_tbl customer_tbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer_tbl).State = EntityState.Modified;
         db.SaveChanges();
         TempData["message"] = "Edit successful!";
         return(RedirectToAction("CustomerManagement"));
     }
     return(View(customer_tbl));
 }
Exemple #16
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,ContactID,AddressType,AddressLine1,AddressLine2,City,StateCode,Zip")] Address address)
        {
            if (ModelState.IsValid)
            {
                db.Entry(address).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(address));
        }
Exemple #17
0
 public ActionResult Edit([Bind(Include = "EventID,EventCatID,LocationID,Name,StartTime,EndTime,OrganiserID")] Event @event)
 {
     if (ModelState.IsValid)
     {
         db.Entry(@event).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EventCatID = new SelectList(db.EventCategories, "EventCatID", "Name", @event.EventCatID);
     ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "Name", @event.LocationID);
     return(View(@event));
 }
Exemple #18
0
        public async Task <ActionResult> Edit([Bind(Include = "DeviceID,LocationID,Build")] Device device)
        {
            if (ModelState.IsValid)
            {
                db.Entry(device).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "Name", device.LocationID);
            return(View(device));
        }
Exemple #19
0
 public IEnumerable<ErrorInfo> SaveModuleType(ModuleType moduleType)
 {
     using(CMSContext context=new CMSContext()) {
         IEnumerable<ErrorInfo> errors=ValidationHelper.Validate(moduleType);
         if(errors.Any()==false) {
             if(moduleType.ModuleTypeID<=0) {
                 context.ModuleTypes.Add(moduleType);
             } else {
                 context.Entry(moduleType).State=EntityState.Modified;
             }
             context.SaveChanges();
         }
         return errors;
     }
 }
Exemple #20
0
 public IEnumerable<ErrorInfo> SavePosition(Position position)
 {
     using(CMSContext context=new CMSContext()) {
         IEnumerable<ErrorInfo> errors=ValidationHelper.Validate(position);
         if(errors.Any()==false) {
             if(position.PositionID<=0) {
                 context.Positions.Add(position);
             } else {
                 context.Entry(position).State=EntityState.Modified;
             }
             context.SaveChanges();
         }
         return errors;
     }
 }
Exemple #21
0
 public ActionResult Edit([Bind(Include = "Id,Name,Password,Type,Contact,EmailAddress")] User_tbl user_tbl)
 {
     if (ModelState.IsValid)
     {
         User_tbl targetUser = db.User_tbl.Find(user_tbl.Id);
         if (db.User_tbl.Where(a => a.EmailAddress == user_tbl.EmailAddress && a.Id != user_tbl.Id).Count() > 0)
         {
             TempData["message"] = "This email has been registered!";
             return(View(user_tbl.Id));
         }
         if (targetUser.Id.ToString() == Session["userId"].ToString())
         {
             targetUser.Password = user_tbl.Password;
         }
         targetUser.Name            = user_tbl.Name;
         targetUser.Contact         = user_tbl.Contact;
         targetUser.EmailAddress    = user_tbl.EmailAddress;
         db.Entry(targetUser).State = EntityState.Modified;
         db.SaveChanges();
         TempData["message"] = "Edit Successful!";
         return(RedirectToAction("AgentManagement", "Agent"));
     }
     return(View(user_tbl));
 }
Exemple #22
0
        public ActionResult Create(List <BookingItem_tbl> items, string schId)
        {
            int  n;
            bool result = int.TryParse(schId, out n);

            if (result == false)
            {
                TempData["message"] = "Please Select a schedule";

                return(Json(Url.Action("Create", "Booking")));
            }
            else if (items == null)
            {
                TempData["message"] = "Please add an item";
                return(Json(Url.Action("Create", "Booking")));
            }
            else if (items != null)
            {
                bool checkItem = true;
                //string message = null;
                int itemCount = 0;
                foreach (var item in items.ToList())
                {
                    if (item.Itm_Id.ToString() == "" || item.Container_No.ToString() == "")
                    {
                        checkItem = false;
                        break;
                    }
                }

                if (checkItem == true)
                {
                    int          scheduleId     = Convert.ToInt32(schId);
                    Schedule_tbl targetSchedule = db.Schedule_tbl.Find(scheduleId);
                    foreach (var item in items)
                    {
                        itemCount = itemCount + item.Container_No;
                    }
                    if (targetSchedule.Available_Container >= itemCount)
                    {
                        Booking_tbl newBooking = new Booking_tbl();
                        newBooking.Bk_Date  = DateTime.Now;
                        newBooking.Agent_Id = Convert.ToInt32(Session["userId"].ToString());
                        newBooking.Sch_Id   = scheduleId;
                        db.Booking_tbl.Add(newBooking);
                        db.SaveChanges();

                        foreach (var item in items.ToList())
                        {
                            BookingItem_tbl newBI = new BookingItem_tbl();
                            newBI.Itm_Id       = item.Itm_Id;
                            newBI.Container_No = item.Container_No;
                            newBI.Bk_Id        = newBooking.Bk_Id;
                            db.BookingItem_tbl.Add(newBI);
                            db.SaveChanges();
                        }


                        targetSchedule.Available_Container = targetSchedule.Available_Container - itemCount;
                        db.Entry(targetSchedule).State     = EntityState.Modified;
                        db.SaveChanges();

                        //message = "New Booking Created!";
                        //return Json(message);
                        TempData["message"] = "New Booking Created!";
                        return(Json(Url.Action("ViewBooking", "Booking")));
                    }
                    else
                    {
                        //message = "Not enought container for the items!";
                        //return Json(message);
                        TempData["message"] = "Not enought container for the items!";
                        return(Json(Url.Action("Create", "Booking")));
                    }
                }
                else
                {
                    //message = "Please make sure all items are added properly!";
                    //return Json(message);
                    TempData["message"] = "Please make sure all items are added properly!";
                    return(Json(Url.Action("Create", "Booking")));
                }
            }

            return(Json(Url.Action("Create", "Booking")));
        }
Exemple #23
0
 public virtual void Update(TEntity entity)
 {
     dbSet.Attach(entity);
     db.Entry(entity).State = EntityState.Modified;
 }