Example #1
0
        public virtual ActionResult Edit(int id, int?parentId, HttpDelete ignore)
        {
            EntityT entityItem = null;

            using (new EFUnitOfWork <DbContextT>())
            {
                try
                {
                    entityItem = RepoFactory.Create <EntityT>().GetById(id);
                    if (parentId == null)
                    {
                        var mvcModelItem = (ChildMvcModelT) new ChildMvcModelT().MapFromObject(entityItem);
                        var parent       = mvcModelItem.GetParentEntity(entityItem);
                        if (parent != null)
                        {
                            parentId = parent.Id;
                        }
                    }
                    entityItem.Delete();
                }
                catch (UnableToDeleteException ex)
                {
                    DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction
                    TempData.Supermodel().NextPageModalMessage = ex.Message;
                }
                catch (Exception)
                {
                    DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction
                    TempData.Supermodel().NextPageModalMessage = "PROBLEM!!!\\n\\nUnable to delete. Most likely reason: references from other entities.";
                }
            }
            return(AfterDelete(id, parentId, entityItem));
        }
Example #2
0
        public void CanDeleteAll()
        {
            Http.Stub(
                HttpDelete
                .Url("https://api.cronofy.com/v1/events")
                .RequestHeader("Authorization", "Bearer " + AccessToken)
                .RequestHeader("Content-Type", "application/json; charset=utf-8")
                .RequestBody("{\"delete_all\":true}")
                .ResponseCode(202)
                );

            Client.DeleteAllEvents();
        }
Example #3
0
        public void CanCloseChannel()
        {
            const string channelId = "chn_54cf7c7cb4ad4c1027000001";

            Http.Stub(
                HttpDelete
                .Url("https://api.cronofy.com/v1/channels/" + channelId)
                .RequestHeader("Authorization", "Bearer " + AccessToken)
                .ResponseCode(202)
                );

            Client.CloseChannel(channelId);
        }
Example #4
0
        public void CanDeleteExternalEvent()
        {
            const string eventUid = "external_event_id";

            Http.Stub(
                HttpDelete
                .Url("https://api.cronofy.com/v1/calendars/" + calendarId + "/events")
                .RequestHeader("Authorization", "Bearer " + AccessToken)
                .RequestHeader("Content-Type", "application/json; charset=utf-8")
                .RequestBodyFormat(@"{{""event_uid"":""{0}""}}", eventUid)
                .ResponseCode(202)
                );

            Client.DeleteExternalEvent(calendarId, eventUid);
        }
Example #5
0
        public void CanDeleteAllForCalendars()
        {
            const string calendar1 = "cal_1234_5678";
            const string calendar2 = "cal_8765_4321";

            Http.Stub(
                HttpDelete
                .Url("https://api.cronofy.com/v1/events")
                .RequestHeader("Authorization", "Bearer " + AccessToken)
                .RequestHeader("Content-Type", "application/json; charset=utf-8")
                .RequestBodyFormat("{{\"calendar_ids\":[\"{0}\",\"{1}\"]}}", calendar1, calendar2)
                .ResponseCode(202)
                );

            Client.DeleteAllEventsForCalendars(calendar1, calendar2);
        }
Example #6
0
        public virtual ActionResult DeleteBinaryFile(int id, string pn, HttpDelete ignore)
        {
            using (new EFUnitOfWork <DbContextT>())
            {
                var entityItem   = RepoFactory.Create <EntityT>().GetById(id);
                var mvcModelItem = (MvcModelT) new MvcModelT().MapFromObject(entityItem);

                //see if pn is a required property
                if (Attribute.GetCustomAttribute(typeof(MvcModelT).GetProperty(pn), typeof(RequiredAttribute), true) != null)
                {
                    TempData.Supermodel().NextPageModalMessage = "Cannot delete required field";
                    var routeValues = new RouteValueDictionary(ControllerContext.RouteData.Values);
                    routeValues["Action"] = "Edit";
                    return(RedirectToRoute(routeValues));
                }

                var file = (BinaryFileMvcModel)mvcModelItem.PropertyGet(pn);

                file.Empty();
                entityItem = (EntityT)mvcModelItem.MapToObject(entityItem);
                return(AfterBinaryDelete(id, entityItem, mvcModelItem));
            }
        }
Example #7
0
        public virtual ActionResult Edit(int id, HttpDelete ignore)
        {
            EntityT entityItem = null;

            using (new EFUnitOfWork <DbContextT>())
            {
                try
                {
                    entityItem = RepoFactory.Create <EntityT>().GetById(id);
                    entityItem.Delete();
                }
                catch (UnableToDeleteException ex)
                {
                    DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction
                    TempData.Supermodel().NextPageModalMessage = ex.Message;
                }
                catch (Exception)
                {
                    DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction
                    TempData.Supermodel().NextPageModalMessage = "PROBLEM!!!\\n\\nUnable to delete. Most likely reason: references from other entities.";
                }
            }
            return(AfterDelete(id, entityItem));
        }