Example #1
0
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="actionValues">action values</param>
        /// <returns>Content result</returns>
        public ContentResult Save(int?id, FormCollection actionValues)
        {
            var action = new DataAction(actionValues);

            //RentalDataContext data = new RentalDataContext();
            RentalDataContext data = new RentalDataContext();

            CarRental.Data.CarRentalDb data1 = new CarRentalDb();

            try
            {
                var changedEvent = (Order)DHXEventsHelper.Bind(typeof(Order), actionValues);

                // find car and change order

                switch (action.Type)
                {
                case DataActionTypes.Insert:

                    data.Orders.InsertOnSubmit(changedEvent);
                    break;

                case DataActionTypes.Delete:
                    changedEvent = data.Orders.SingleOrDefault(ev => ev.id == action.SourceId);
                    data.Orders.DeleteOnSubmit(changedEvent);
                    break;

                default:
                    var eventToUpdate = data.Orders.SingleOrDefault(ev => ev.id == action.SourceId);
                    EventUpdate(eventToUpdate, changedEvent);
                    break;
                }
                data.SubmitChanges();
                action.TargetId = changedEvent.id;
            }
            catch
            {
                action.Type = DataActionTypes.Error;
            }

            return(Content(new AjaxSaveResponse(action), "text/xml"));
        }
Example #2
0
 public DB()
 {
     carRental = new CarRentalDb();
 }